Solved

Pause a VB script until after startup

Posted on 2007-03-22
10
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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
 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

726 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