Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vbscript opens a clickonce app needs to wait until running

Posted on 2009-07-15
7
Medium Priority
?
1,344 Views
Last Modified: 2012-05-07
I have a script that opens a vb.net clickonce app.  I need the script to wait until the app is updated and running before doing anything,  Now I have a wait in there but depending on a users machine, my delay is either too long or too short.  I would like to be able to check processes running.  Anyone else doing this?  Code Below.
So instead of "autECLSession.autECLPS.Wait 1300" I want something like wait till myApp.exe is running.
Dim objShell : Set objShell = CreateObject("WScript.Shell")
dim UserDesktopProgram
 
  UserDesktopProgram = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Start Menu\Programs\AiF\Op.appref-ms"
 
objShell.Run chr(34) & UserDesktopProgram & chr(34)
autECLSession.autECLPS.Wait 1300
 
objShell.SendKeys auth
 
objShell.SendKeys"{TAB}"
objShell.SendKeys op
objShell.SendKeys"{TAB}"

Open in new window

0
Comment
Question by:bergertime
[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
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:TerryInOhio
ID: 24860048
This might give you an idea.
I copy a virus defination file to a users PC and once complete start it running.  The only way I could assure that the file has been copied before the install starts is to break the code into 2 scripts.
WSHShell.run strLogOnPath & "VirusUpdate.vbs", 0, true
WSHShell.run strLogOnPath & "VirusUpdateRun.vbs", 0, true
The 'true' parameter causes the wait until complete.
0
 
LVL 1

Expert Comment

by:galaxip
ID: 24861037
if you need to check if a process is running, call something like this in between short waits, just pass in myApp.exe:

Function isRunning(sApplication)
    Dim oWmiSvc  
    Dim colProcesses
    Dim oProcess
    Dim sComputer 
    Dim sList
 
    sComputer = "."
 
    Set oWmiSvc = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
    Set colProcesses = oWmiSvc.ExecQuery ("Select * from Win32_Process")
 
    isRunning = False
    For Each oProcess in colProcesses
        If oProcess.Name = sApplication Then
            isRunning = True
        End If
    Next
End Function

Open in new window

0
 
LVL 2

Author Comment

by:bergertime
ID: 24861245
where would I pass myapp.exe?  Could I put this in a loop until isrunning  is true?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:galaxip
ID: 24861480
Yes, call the function from within a loop, but be careful to allow for if the executable NEVER runs.
You might want to limit how many wait cycles are tried. Maybe by using something like snippet below.

Also, realize that if myapp.exe stops running for whatever reason, the isRunning function would then fail to find it. So if myapp.exe finishes very fast, the code snippets provided could miss it.

For i = 1 to 90
    'put your wait code here
    If isRunning("myApp.exe") Then
        'put code here you want to run if myapp.exe is running
    End If
Next

Open in new window

0
 
LVL 2

Author Comment

by:bergertime
ID: 24861831
Ok, you have me so close, I need to exit the loop so something like below:

If isRunning("myApp.exe") Then
       exit loop<<<<<<<<<<<<<<<<<<<<<<
    End If
Once the App is up, it should stay up, it's just a matter of how long it takes the slower computers to get the app running, so can I exit the loop?
0
 
LVL 1

Expert Comment

by:galaxip
ID: 24861978
Try "Exit For"...

For i = 1 to 90
    'put your wait code here
    If isRunning("myApp.exe") Then
        'put code here you want to run if myapp.exe is running
        Exit For
    End If
Next

Open in new window

0
 
LVL 1

Accepted Solution

by:
galaxip earned 2000 total points
ID: 24862591
If you only want to pause your script until myapp.exe has finished running, there is another way.
This code shows how to run notepad.exe, and will put up a message box when notepad exits.
    sApplication = "C:\WINDOWS\\system32\notepad.exe"
 
    'script execution will wait for sApplication to finish running
    Dim oShell
  
    'put code here to perform before sApplication runs
    wscript.echo "notepad.exe is about to run"
    
    'this code runs the application
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run """" & sApplication & """", 1, True
 
    'put code here to perform after sApplication finishes
    wscript.echo "notepad.exe has been closed"

Open in new window

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.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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