Link to home
Start Free TrialLog in
Avatar of MightySW
MightySWFlag for United States of America

asked on

How to close correct window with this VBS

Hi guys, just wondering how to script this correctly to wait for the window to run the secureCRT application and THEN close the window.  Right now it is closing the first window that is open.  If I run this from explorer or from cscript from dos it will close those windows and then run secureCRT.  

Please help

Thanks
Dim objShell
Set objShell = Wscript.CreateObject("Wscript.Shell") 
 
objShell.run(Chr(34) & "C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.EXE" & chr(34) & " /script D:\logs\Scripts\recordedScript.vbs")
 
 
objShell.AppActivate "192.168.1.79 - SecureCRT"
 
objshell.SendKeys "%{F4}"

Open in new window

Avatar of TakedaT
TakedaT
Flag of United States of America image

I dont have the application to test, but you can try to add the bWaitOnReturn to the  run line like so.  Then you can also test for the return value depending on what it is.  If you want to run it from the cmd line, then you can begin the run line with a "cmd /c start" or something like that.

 Let me know how it works.
Dim objShell
Set objShell = Wscript.CreateObject("Wscript.Shell") 
 
iReturn = objShell.run(Chr(34) & "C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.EXE" & chr(34) & " /script D:\logs\Scripts\recordedScript.vbs",1,True)
 
If iReturn = 0 then
	Success = objShell.AppActivate("192.168.1.79 - SecureCRT")
	If Success then
		wscript.sleep 100
		objShell.SendKeys "%{F4}"
	End if
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MightySW

ASKER

Thanks for the reply.  I tried the loop (exactly how you have it) and everything opens fine, but secureCRT still will not close.  At least nothing closed now.  Seems that the boolean is either set too soon, or success lost its value.  
I'll try it.
From one MASTA TO ANOTHAHHH

Thanks bro, that did it!

Where did you find that dang command?  I even looked at the script manual for SecureCRT.
Thanks, I left a follow up question.

Can you just post the link.

Thanks again.  See you on the forums.
Just FYI and for anybody else that runs into this issue

Do this:

crt.Screen.Synchronous = False
before
crt.quit or else it will not write anything before disconnecting.
I think it was this one:
http://forums.vandyke.com/showthread.php?t=1204

I also just ran across this one that looks useful:
https://www.vandyke.com/support/tips/scripting/creating.html

The more Im reading about this prog, the more I think I want to give it a try.  Could be mighty useful with all the cisco equipment I have to manage.  Thanks for the tip :D
yeah, SecureCRT is by far the best when dealing with Cisco equipment.  It was recommended to me by a CCIE a long time ago and is still the preferred program for Cisco equipment.  Very versatile and cheap.

Thanks again for your help.  It is running well now.