troubleshooting Question

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

Avatar of Lico_w
Lico_w asked on
VB Script
2 Comments1 Solution254 ViewsLast Modified:
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
	monitorSS(newLog)
	newLog = newLog + 1
next

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

	oShell.Run sCmd & logNo
	WScript.Sleep 500
	oShell.AppActivate "C:\Windows\system32\cmd.exe"
	oShell.SendKeys("^]")
	WScript.Sleep 500
	oShell.AppActivate "C:\Windows\system32\cmd.exe"
	oShell.SendKeys("quit{ENTER}")
	WScript.Sleep 500

	set oShell = nothing
end function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros