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
Solved

Pause a VB script until after startup

Posted on 2007-03-22
10
204 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 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