How to grab a hidden or minimised DOS prompt and then use the SendKeys method

Lico_w used Ask the Experts™
I have a simple script which runs a bat file, which opens up a telnet session to a box and port, dumps the output to a logfile and then closes the connection, discussed in the following article: 27238825.However the only way to close it due to various issues is to grab the DOS window and do a SendKey of CTRL + ] and then a sendkey of quit, then enter.

This works fine when the telnet session is opened normally however there is a flaw. If the user clicks onto a separate window whilst the command is running, the sendkeys go to that window and dont close the telnet session. I would ideally like the DOS screen to be hidden or minimised so users don't see it. To do that I would need to grab the window manually I guess and then do the sendkeys thing. My script is below
newLog = 1

for i = 1 to 10
	newLog = newLog + 1

function monitorSS(logNo)
	sCmd = "monitorSS.bat "
	Set oShell = CreateObject("") 

	oShell.Run sCmd & logNo
	WScript.Sleep 500
	oShell.AppActivate "C:\Windows\system32\cmd.exe"
	WScript.Sleep 500
	oShell.AppActivate "C:\Windows\system32\cmd.exe"
	WScript.Sleep 500

	set oShell = nothing
end function

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Did you try to use taskkill COMMAND?

See: taskkill /?
monitorSS.bat would becomes the windows title too in order to kill the process.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial