?
Solved

Pause a VB script until after startup

Posted on 2007-03-22
10
Medium Priority
?
227 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
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

777 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