0

I'm trying to write a script in vb to open a telnet session to a remote windows CE7 device from a Windows 7 laptop to get the output from ipconfig /all to a text file, then append the contents of that text file to a log. So far I've only been able to do this by running the vb script, then running an ftp script to retrieve the log from the device. I haven't figured out how to get that file's contents copied into a main log file.

This is my vb script:

Set OBJECT = CreateObject("WScript.Shell")
OBJECT.run"cmd"
WScript.Sleep 800

OBJECT.SendKeys"telnet ipaddress" OBJECT.SendKeys("{Enter}") WScript.Sleep 800

OBJECT.SendKeys"admin" OBJECT.SendKeys("{Enter}") WScript.Sleep 800

OBJECT.SendKeys"admin" OBJECT.SendKeys("{Enter}") WScript.Sleep 800

OBJECT.SendKeys"ipconfig /all >> somelog.log" OBJECT.SendKeys("{Enter}") WScript.Sleep 800

OBJECT.SendKeys"^]" WScript.Sleep 800 OBJECT.SendKeys"quit" OBJECT.SendKeys("{Enter}") WScript.Sleep 800 OBJECT.SendKeys"exit" OBJECT.SendKeys("{Enter}")

I then run a batch file that runs an ftp file:


open 172.16.24.45
admin
admin
get "sendkeys.log"
close

I'd love to automate this entire process and get it done with 1 file. Any help is greatly appreciated.

1
  • 1
    Just run both from the same batch file? – Ramhound Aug 22 '13 at 21:33
0

The following commands should do what you're asking. Copy and save them into a .bat or .cmd file. Please note that any file names surrounded by <> are meant to be replaced by the actual file names from your system, do not enter the < or > in the script, or undesirable results will happen.

cscript.exe //nologo <vbsendkeys_script.vbs>
call <ftpget.bat>
copy <masterlog.log> + sendkey.log mastertemp.log
del <masterlog.log>
ren mastertemp.log <masterlog.log>

The cscript.exe is the command line script host for windows. It will run the .vbs you specify and output results (if any) on the command line.

Call is used to run another batch file and then return execution to the original (calling) batch file. Without using call, both batch files would terminate after the second one was run.

The rest of the commands copy the sendkey.log to the end of the master log and do some renaming and cleanup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.