Solved

How to close correct window with this VBS

Posted on 2009-07-07
10
738 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now