Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a vb script that will wrap around an applcation which will stay open until the application finishes. I want to be able to call the following command

"setup.exe /qb /I Autocad2010.ini /language en-us"

But I need the vb script to stay running until the setup has finished.

Is there anyone out there that can assist with this.

Much appreciated in advance

share|improve this question
    
Are you trying to use VB to deploy Autocad to a bunch of computers? If that's what you're trying to accomplish you may want to have a look at wpkg.org. They will provide you a app deployment mechanism that can run pre and post install commands or scripts. – 3dinfluence Mar 5 '10 at 3:19
    
I am trying to deploy autocad with MDT but the apps keep trying to start before the other finishes. So i was told that if I run a vbscript around the apps that MDT will see it as an app and wait for it to finish. The packages I have are from the deployment on the autocad discs. – JohnyV Mar 5 '10 at 3:46
up vote 1 down vote accepted

Updated version

The following will execute your setup program, then wait for there to be no more instances of setup.exe running. There is a maximum timeout value you can set (so that it doesn't hang forever).

Please note that this can't detect whether setup is done, only whether or not a setup.exe process is running. It's a minor distinction, but an important one.

Option Explicit

Const PROC_NAME = "setup.exe"
Const RUN_CMD = "setup.exe /qb /I Autocad2010.ini /language en-us"
Const SLEEP_INTERVAL_MS = 1000
Const WAIT_TIMEOUT_MS = 1500000 ' = 1000 * 60 * 25 ms = 25 mins

Dim objWshShell, objWMIService
Dim colProcesses, objProcess
Dim intWaited, blnProcessTerminated

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run RUN_CMD

intWaited = 0
blnProcessTerminated = False
While intWaited < WAIT_TIMEOUT_MS And Not blnProcessTerminated
    Set colProcesses = objWMIService.ExecQuery(_
        "Select * from Win32_Process where Name='" & PROC_NAME & "'")

    blnProcessTerminated = True
    For Each objProcess In colProcesses
        blnProcessTerminated = False
    Next

    WScript.Sleep(SLEEP_INTERVAL_MS)
    intWaited = intWaited + SLEEP_INTERVAL_MS
Wend

This is relatively straightforward:

Option Explicit

Dim objWshShell
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run "setup.exe /qb /I Autocad2010.ini /language en-us", 1, True

The parameters to the Run method are described in greater detail on the MSDN site. Most importantly, True causes the script to wait until setup.exe has terminated.

share|improve this answer
    
Thanks I will try this out. – JohnyV Mar 5 '10 at 7:37
    
I tried this script but the script stops before the setup.exe is finsihed. Therefore MDT thinks that the application has stopped installing and continues on its task sequence. – JohnyV Mar 7 '10 at 21:46
    
The script waits until that setup.exe finishes – but it could be that setup.exe launches another instance of itself. I'll update my answer with a version that waits until no setup.exe is detected to be running on the system. – fission Mar 7 '10 at 23:00
    
Is the version above the edited version? (I deleted the packages that I was using that had the old script in it so I cant compare)? – JohnyV Mar 8 '10 at 6:06
    
No, sorry – I got stuck on the tarmac, unable to upload the new version for much longer than expected. Here you go; the new version is up. – fission Mar 8 '10 at 7:15

I know this is pretty old, but I'm looking to do something similar.

I want to execute a command. This command after a second or two will launch an additional process. This is the process I want to watch.

This process will start and stop (only closed briefly before restarting). As it performs different functions.

My end goal is to keep the script running, until the 2nd process has been not running for "x" seconds.

I think the problem I may run into, is that each of those processes will have the same name, but a different process ID.

I tried to take this over to the MS Scripting Guys forum but ran into a wall (jrv).

Option Explicit

Const PROC_NAME = "radpinit.exe" Const RUN_CMD = "cmd /c ""C:\Program Files (x86)\Novadigm\radntfyc.exe"" LOCALHOST Radskman.exe cat=prompt,ulogon=n,hreboot=y,context=m,mname=radia,dname=SOFTWARE,ip=server.domain.com,port=8000,uid=$MACHINE,startdir=SYSTEM,ind=y,cop=y,log=software_connect.log" Const SLEEP_INTERVAL_MS = 1000 Const WAIT_TIMEOUT_MS = 30000 ' = 1000 * 60 * 25 ms = 25 mins

Dim objWshShell, objWMIService Dim colProcesses, objProcess Dim intWaited, blnProcessTerminated

Set objWMIService = GetObject("winmgmts:\.\root\cimv2") Set objWshShell = WScript.CreateObject("WScript.Shell") objWshShell.Run RUN_CMD

intWaited = 0 blnProcessTerminated = False While intWaited < WAIT_TIMEOUT_MS And Not blnProcessTerminated Set colProcesses = objWMIService.ExecQuery(_ "Select * from Win32_Process where Name='" & PROC_NAME & "'")

blnProcessTerminated = True
For Each objProcess In colProcesses
    blnProcessTerminated = False
Next

WScript.Sleep(SLEEP_INTERVAL_MS)
intWaited = intWaited + SLEEP_INTERVAL_MS
share|improve this answer
    
This seems like it's another question, not an answer. If so, you should create a new question for it. Answers are really just for answers to the question. – Eric Renouf Nov 3 '15 at 13:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.