• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Pause a VB script until after startup

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
pscanevit
Asked:
pscanevit
  • 6
  • 4
1 Solution
 
sirbountyCommented:
This looks familiar... ;^)
Simply 'pause' the script with

wscript.sleep 20000 'pause 20 seconds

0
 
pscanevitAuthor Commented:
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
 
sirbountyCommented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sirbountyCommented:
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
 
pscanevitAuthor Commented:
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
 
sirbountyCommented:
Can you post all 3?  If not here, at www.ee-stuff.com
0
 
pscanevitAuthor Commented:
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
 
sirbountyCommented:
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
 
pscanevitAuthor Commented:
This works great!  Thanks for all of your help.
0
 
sirbountyCommented:
Much obliged.
Thanx for the grade! :^)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now