Lico_w
asked on
How do I close a WSCript.shell object in VBScript?
I have the following code running to monitor some software:
Set oShell = CreateObject("WSCript.shel l")
hidden = 0
minimised = 7
logF = 1
sCmd = "monitorSS.bat "
testPort(logF)
function testPort(logFile)
newLog = logFile + 1
'sCmd = "monitorSS.bat test abc"
'newLog = "test8910"
'Run the BAT file.
oShell.Run sCmd & newLog, 0, false 'find out what false does
oShell.quit
if newLog < 10 then _
testPort(newLog)
end function
This calls a bat file which telnets to a port and dumps out the response to a logfile. However the connection is not closing hence the 2nd 3rd 4th etc attempts are unable to telnet on that port.
Any help appreciated.
Set oShell = CreateObject("WSCript.shel
hidden = 0
minimised = 7
logF = 1
sCmd = "monitorSS.bat "
testPort(logF)
function testPort(logFile)
newLog = logFile + 1
'sCmd = "monitorSS.bat test abc"
'newLog = "test8910"
'Run the BAT file.
oShell.Run sCmd & newLog, 0, false 'find out what false does
oShell.quit
if newLog < 10 then _
testPort(newLog)
end function
This calls a bat file which telnets to a port and dumps out the response to a logfile. However the connection is not closing hence the 2nd 3rd 4th etc attempts are unable to telnet on that port.
Any help appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can we see the batch file? I suspect that it will be best to determine why the telnet does not close and fix that first.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or maybe I'm just plainly talking rubbish about the quit method after checking MSDN, doh. Still, the rest of it may or may not help...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, if you *do* use the Exec method (objShell.Exec) you can use the Terminate method if that helps.
Set objExec = objShell.Exec("monitorSS.b at")
' ......
objExec.Terminate
Rob.
Set objExec = objShell.Exec("monitorSS.b
' ......
objExec.Terminate
Rob.
ASKER
RobS using your way does terminate it, however the bat doesn't seem to run properly i.e. no response from the port and no logging???
I've attached the simple bat file for those who requested below:
@ECHO OFF
echo %1
telnet -f telnet%1.log <ip address> <port>
The issue is that once the BAT file connects via telnet it isn't quitting. I cant get it to close the connection regardless. I've tried typing quit, close, exit etc. nothing seems to break the connection other than closing the DOS window. This is what I need to resolve
I've attached the simple bat file for those who requested below:
@ECHO OFF
echo %1
telnet -f telnet%1.log <ip address> <port>
The issue is that once the BAT file connects via telnet it isn't quitting. I cant get it to close the connection regardless. I've tried typing quit, close, exit etc. nothing seems to break the connection other than closing the DOS window. This is what I need to resolve
I don't think that it is possible to send commands to telnet after it is started in a script like this. Are you actually connecting to a telnet server, or a different service. If you are not connecting to a telnet server, you could use netcat quite easily. Something like the following:
http://joncraton.org/blog/46
nc <ip address> <port> < netcatcommands.txt > nc.log
You can get a windows version of netcat here:http://joncraton.org/blog/46
I'm going to explore a slightly different approach, will report back if it yields anything useful...
~bp
~bp
ASKER
Thanks bp.
Sterling my internet policy won't allow me to download this!
One way I was thinking was to open the telnet session minimised, then close the window via a script. Not sure how that could be done though....
Sterling my internet policy won't allow me to download this!
One way I was thinking was to open the telnet session minimised, then close the window via a script. Not sure how that could be done though....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your suggestions, but I'd rather not download additional software especially as it seems it can be done through the telnet comand set. I have just found that the telnet session can be terminated manually with a CTRL + ]. However I'm struggling to do this through the script. My basic code is below, can anyone suggest what I'm doing wrong?
Set oShell = CreateObject("WSCript.shell")
newLog = "1"
sCmd = "monitorSS.bat "
oShell.Run sCmd & newLog
oShell.SendKeys("^]")
oShell.SendKeys("quit")
ASKER
Never mind I sussed it out. I just needed a sleep delay in there. Thanks for all imputs I'll try to be fair when awarding points
Just curious, there are a few free telnet controls that you could use directly from VBS to automate the telnet connection to your server, and then process the output right in VBS. Before I go too far down that path, would you be able to install such a control on the server that will be running the script, or is that not allowed?
~bp
~bp