Solved

How to close correct window with this VBS

Posted on 2009-07-07
10
741 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
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 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
 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SLMGR Switches Are Not Working On KMS Host 3 92
How can I sort the data shown in Sheet 1 and copy it to Sheet 2? 8 51
Problem to With line 4 57
RUNRMTCMD from AS/400 12 47
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

772 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