Hi,
I'm using shell to run a program, and I want my VB program to wait until the process is finished. Unfortunately the program is constructed in such way that it opens a new process, so I have to get the processhandle before i can use WaitforSingleObject.
I found some code that Jmarler posted that returns the processID. As I understand it the ProcessID is not the same as the Process Handle And I'm now asking for help to modify the code to return the handle so I can wait for the new process (or any other code that will work).
This is what I got (notepad is just an example of course):
----------------------------------------------------------
Dim hproc As Long, WaitReturn As Long
Shell "notepad"
hproc = GetProcessHandle("notepad.exe"
If hproc <> 0 Then
WaitReturn = WaitForSingleObject(hproc, -1&)
If WaitReturn = WAIT_FAILED Then MsgBox "Wait failed"
CloseHandle hproc
End If
----------------------------------------------------------
But WaitForSingleObject keeps returning WAIT_FAILED
JMarlers code is posted at thread222-69608
Sunaj
I'm using shell to run a program, and I want my VB program to wait until the process is finished. Unfortunately the program is constructed in such way that it opens a new process, so I have to get the processhandle before i can use WaitforSingleObject.
I found some code that Jmarler posted that returns the processID. As I understand it the ProcessID is not the same as the Process Handle And I'm now asking for help to modify the code to return the handle so I can wait for the new process (or any other code that will work).
This is what I got (notepad is just an example of course):
----------------------------------------------------------
Dim hproc As Long, WaitReturn As Long
Shell "notepad"
hproc = GetProcessHandle("notepad.exe"
If hproc <> 0 Then
WaitReturn = WaitForSingleObject(hproc, -1&)
If WaitReturn = WAIT_FAILED Then MsgBox "Wait failed"
CloseHandle hproc
End If
----------------------------------------------------------
But WaitForSingleObject keeps returning WAIT_FAILED
JMarlers code is posted at thread222-69608
Sunaj