|
-
Jan 8th, 2002, 09:56 AM
#1
Thread Starter
Hyperactive Member
ShellExecute and Wait???
At one point in my program, it is necessary to shell a document(of which I do not know the default program to launch it). To avoid this problem, I used the ShellExecute API command. The problem is now, for some reason the processid that is being returned is not successfully working with my code.
Code:
processid = ShellExecute(Me.hwnd, vbNullString, pathtofile, commandline, "C:\", vbNormalFocus)
processhandle = OpenProcess(SYNCHRONIZE, 0, processid)
This worked fine before with Shell. It stil returns a non-zero processid, but it no longer establishes a non-zero process handle. How do I fix this? Thank you very much for the help.
Joe
Last edited by Joey_k29; Jan 8th, 2002 at 11:22 AM.
-
Jan 8th, 2002, 12:18 PM
#2
Give this a shot...
VB Code:
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Function ShellAndWait(PathName As String, Optional WS As VbAppWinStyle = vbMinimizedFocus) As Double
'
Dim lhProcess As Long
Dim lExitcode As Long
Dim dProcessID As Double
'
On Error GoTo errShellAndWait
dProcessID = Shell(PathName, WS)
lhProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, dProcessID)
Do
Call Sleep(50): DoEvents
Call GetExitCodeProcess(lhProcess, lExitcode)
Loop While (lExitcode = STILL_ACTIVE)
CloseHandle (lhProcess)
ShellAndWait = dProcessID
Exit Function
errShellAndWait:
If lhProcess <> 0 Then
CloseHandle (lhProcess)
End If
ShellAndWait = dProcessID
End Function
-
Jan 8th, 2002, 01:04 PM
#3
Thread Starter
Hyperactive Member
Thank you but...
It does not work with shell execute. I am not even shell executing a document(which could potentially cause a problem); I am executing an exe. Thanks for the suggestion.
Joe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|