Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to WAIT for ShellExecute process to complete?

Status
Not open for further replies.

cmackenz

Programmer
Oct 29, 2003
3
CA
I have a line of code:

objShell.ShellExecute strApp, strCommand, "", "RunAs", 1

strApp is either cscript.exe and wscript.exe
strCommand is the path of a .wsh file that I create to run a second script.

I need my main script to run this command, and then WAIT for the strApp to finish before continuing.

Anyone know how that can be accomplished?

Many thanks!
 
Thank you, mrmovie, but I don't think that's what I'm after. How would you add privilege elevation for Vista to this? With the ShellExecute command, I don't need to specify a specific user name/password, but just specify "runas" and I end up prompted to click a button to allow admin access to run the command. With the "Run" command you've given, the script would just run in the logged-in user's context.

I did read something about ShellExecuteEx, but I'm not sure how to add that in VBScript, in place of what I have.

I'm sort of a novice programmer in this space.
 
if you insist on using .Exec method then you need to stay in a loop waiting for the .Status to become 0 i believe
Exit.vbs
' VBScript to demonstrate exit code.
' Authors Keith Hubbard and Guy Thomas
' Version 1.2 - November 2006
Option Explicit
Dim objShell, objExec
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("Calc")
Do While objExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo "Calc Closed Status = " & objExec.Status
WScript.Quit
 
Sorry if I'm missing something obvious. The 'Exec' method will let me wait for return, but can I somehow pass "RUNAS" to that? I don't see the option with the 'Exec' method that I see with the 'ShellExecute' method. Similarly, I don't see an option with 'ShellExecute' that lets me wait for return. It seems to be that I get one or the other feature, but not both features together in one method. Many thanks for any help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top