Solved

Pause a VB script until after startup

Posted on 2007-03-22
10
186 Views
Last Modified: 2010-04-16
I have a really complicated issue (well I think it is anyways).  I have a send keys script that I want to launch via GP and a logon script.  However it crashes because it tries to start before all services are up and the send keys codes are getting confused.  Is there a way I can stall this script until after all other services have started and the script can run without interruptions.  Be Gentle I'm new at scripting.  Oh, below is the script.
Dim objShell: Set objShell = CreateObject("Wscript.Shell")
Dim objFSO: Set ObjFSO = CreateObject("Scripting.FileSystemObject")

strHost="vpn1.cbi-sa.com"
strCo="CBI-VPN1new"

If Not objFSO.fileexists("C:\Documents and Settings\All Users\Desktop\CBI-VPN1new.lnk") then

With objShell
  .Run "Control ncpa.cpl"            
  wscript.sleep 4000
  .AppActivate "Network Connections"
  wscript.sleep 4000
  .SendKeys "%FN"
  wscript.sleep 4000
  .SendKeys "%N"  
  wscript.sleep 4000
  .SendKeys "%v"
  wscript.sleep 4000
  .Sendkeys "%N%d"
  wscript.sleep 4000
  .Sendkeys "%N%H" & strHost & "%N"
  wscript.sleep 4000
  .SendKeys "%F%N"
  wscript.sleep 4000
  .SendKeys strCo & "%s{TAB}{TAB}~"
  End With
End IF


0
Comment
Question by:pscanevit
  • 6
  • 4
10 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18774931
This looks familiar... ;^)
Simply 'pause' the script with

wscript.sleep 20000 'pause 20 seconds

0
 

Author Comment

by:pscanevit
ID: 18775056
I'm sorry to be your never ending nightmare.  Where in the script would I put this pause so it'll work? And how long can I pause it for?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18775083
You'd put it right there at the top...you can pause it for as long as you like..it's in milliseconds, so 1000 is 1 second...

But hold a sec - I think I may have a better alternative..
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18775105
Something like this perhaps...it'll test for control.exe and won't run the remainder of the script until that process is launched...

With objShell
  .Run "Control ncpa.cpl"            
'add the following...
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMI.ExecQuery("Select * from Win32_Process Where Name='control.exe'")
Do While colProcess.Count < 1
wscript.sleep 2500
Loop
'add the rest of your script here
0
 

Author Comment

by:pscanevit
ID: 18780037
This works great, but my project just more complicated.  I have 3 vpn connections to change which mean three separate scripts.  There's now way I can run 3 separate scripts at logon so I either combine them or come up with another solution.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18780117
Can you post all 3?  If not here, at www.ee-stuff.com
0
 

Author Comment

by:pscanevit
ID: 18789830
they are all three the same only changing out the strhost and strco.
strhost - vpn1.cbi-sa.com, vpn2.cbi-sa.com, vpn3.cbi-sa.com
strco - cbi-vpn1new, cbi-vpn2new, cbi-vpn3new
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18791871
So, the 'one' file could look like:

arrHost=Array("vpn1.cbi-sa.com","vpn2.cbi-sa.com","vpn3.cbi-sa.com")
arrCo=Array("CBI-VPN1new","CBI-VPN2new","CBI-VPN3new")

For x = 0 to ubound(arrHost)

If Not objFSO.fileexists("C:\Documents and Settings\All Users\Desktop\" & arrCo & ".lnk") then

With objShell
  .Run "Control ncpa.cpl"            
  wscript.sleep 4000
  .AppActivate "Network Connections"
  wscript.sleep 4000
  .SendKeys "%FN"
  wscript.sleep 4000
  .SendKeys "%N"  
  wscript.sleep 4000
  .SendKeys "%v"
  wscript.sleep 4000
  .Sendkeys "%N%d"
  wscript.sleep 4000
  .Sendkeys "%N%H" & arrHost(x) & "%N"
  wscript.sleep 4000
  .SendKeys "%F%N"
  wscript.sleep 4000
  .SendKeys arrCo(x) & "%s{TAB}{TAB}~"
  End With
End IF

Next

Set objShell=Nothing
0
 

Author Comment

by:pscanevit
ID: 18850457
This works great!  Thanks for all of your help.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18850466
Much obliged.
Thanx for the grade! :^)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

11 Experts available now in Live!

Get 1:1 Help Now