View Single Post
Old 09-09-2006, 04:52 PM
dilettante's Avatar
dilettante dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,533

As a total .Net newbie I've recently been tearing my hair out once again trying to wrap my head around the way socket I/O is done. I've been amazed at the small number and poor quality of examples and descriptive text on the subject. That includes those from Microsoft.

Ignorant diatribe aside though, have you considered another solution? Say, something that doesn't require hacking together a program in VB.Net or C#?

For this very kind of thing I've found a handy free ActiveX component from Dimac to be just the ticket. I've used it for lots of little administrative tasks, from pinging HTTP servers to performing remote functions via Telnet just as you've described.

As I said, it's free - though they will make you register to get the download: Dimac Free Downloads. Once you have this installed you can handily script your way to a solution. Here's an example:

Set w3sock = CreateObject("socket.tcp") With w3sock .DoTelnetEmulation = True .TelnetEmulation = "TTY" .Host = "localhost:23" .Open .WaitFor "login:" .SendLine "YOURUSERID" .WaitFor "password:" .SendLine "YOURPASSWORD" .WaitFor ">" .SendLine "prompt $LREADY$G" .WaitFor "<READY>" .SendLine "dir c:\windows\repair" .WaitFor "<READY>" 'Parse echoed DIR line and trailing <READY> off results. WScript.Echo Split(Split(.Buffer, vbNewLine, 2)(1), "<READY>")(0) .Close End With Set w3sock = Nothing
This is just a trivial example, but perhaps close to what you need. Run it from a command line or within a BAT/CMD file as in:

cscript //nologo FetchDir.vbs

My results look like:
 Volume in drive C is System
 Volume Serial Number is F8B2-FA88

 Directory of c:\windows\repair

07/28/2006  05:39 PM    <DIR>          .
07/28/2006  05:39 PM    <DIR>          ..
08/23/2001  08:00 AM             1,688 autoexec.nt
07/28/2006  05:38 PM             2,577 config.nt
07/28/2006  05:43 PM           237,568 default
07/28/2006  05:43 PM            24,576 sam
07/28/2006  05:39 PM           787,668 secsetup.inf
07/28/2006  05:43 PM            28,672 security
07/28/2006  05:36 PM           208,626 setup.log
07/28/2006  05:43 PM         8,175,616 software
07/28/2006  05:43 PM         1,081,344 system
               9 File(s)     10,548,335 bytes
               2 Dir(s)  12,895,301,632 bytes free

Last edited by dilettante; 09-09-2006 at 04:55 PM. Reason: typo
Reply With Quote