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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do shell a program & keep that program active until terminated?

Status
Not open for further replies.

JH0401

Programmer
Apr 5, 2002
15
0
0
US
Hi,

I need to shell a program & then keep that program as the
active program until it is terminated by the user.

Any help appreciated.

Thanks,

Josh
 
I think there are various ways to accomplish this, but I always use CreateProcess and WaitForSingleObject for this.

CreateProcess will provide you with a handle to the newly created process and, by supplying this handle to the WaitForSingleObject, you can wait for the process to have been terminated.
Greetings,
Rick
 
As an option to the one posited by LazyMe, you can use the Windows Host Scripting Object, which you add as a project reference.

Dim RetVal As Long
Dim WSH As IWshShell
Dim WaitForTerm as Boolean
Dim CommandLine as String

Set WSH = New IWshShell_Class
CommandLine = "notepad.exe"
WaitForTerm = True
RetVal = WSH.Run(CommandLine, vbNormalFocus, WaitForTerm)
' MsgBox "Process returned: " & RetVal
Set WSH = Nothing Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion & LazyMe,

Thank you for your helpful replies. If I need to create a batch file to open a process, how can I get the handle for the new window opened by the batch? Should this be a new thread?

Thanks,

Josh
 
I've never used it, but GetGUIThreadInfo returns lots of window handles. I'm not sure i it will work, but you can give it a try......
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top