Solved

How to close correct window with this VBS

Posted on 2009-07-07
10
739 Views
Last Modified: 2013-12-26
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

0
Comment
Question by:MightySW
  • 7
  • 3
10 Comments
 
LVL 10

Expert Comment

by:TakedaT
ID: 24799130
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

0
 
LVL 10

Accepted Solution

by:
TakedaT earned 500 total points
ID: 24799258
I just googled it and it looks like since you are using a vbscript inside the program, you should just add "crt.quit"  to the end of the "recordedscript.vbs" file that you are calling.  Then there is no need to use the appactivate or sendkeys method in your original code.
0
 
LVL 20

Author Comment

by:MightySW
ID: 24799264
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.  
0
 
LVL 20

Author Comment

by:MightySW
ID: 24799269
I'll try it.
0
 
LVL 20

Author Comment

by:MightySW
ID: 24799293
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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 20

Author Closing Comment

by:MightySW
ID: 31600857
Thanks, I left a follow up question.

Can you just post the link.

Thanks again.  See you on the forums.
0
 
LVL 20

Author Comment

by:MightySW
ID: 24799316
0
 
LVL 20

Author Comment

by:MightySW
ID: 24799408
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.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24801274
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
0
 
LVL 20

Author Comment

by:MightySW
ID: 24804708
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now