Results 1 to 3 of 3

Thread: ShellExecute and Wait???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Give this a shot...
    VB Code:
    1. Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    2. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Const PROCESS_QUERY_INFORMATION = &H400
    6.  
    7.  
    8. Private Function ShellAndWait(PathName As String, Optional WS As VbAppWinStyle = vbMinimizedFocus) As Double
    9. '
    10.     Dim lhProcess As Long
    11.     Dim lExitcode As Long
    12.     Dim dProcessID As Double
    13. '
    14.     On Error GoTo errShellAndWait
    15.  
    16.     dProcessID = Shell(PathName, WS)
    17.     lhProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, dProcessID)
    18.     Do
    19.         Call Sleep(50): DoEvents
    20.         Call GetExitCodeProcess(lhProcess, lExitcode)
    21.     Loop While (lExitcode = STILL_ACTIVE)
    22.     CloseHandle (lhProcess)
    23.     ShellAndWait = dProcessID
    24.    
    25.     Exit Function
    26.  
    27. errShellAndWait:
    28.     If lhProcess <> 0 Then
    29.         CloseHandle (lhProcess)
    30.     End If
    31.     ShellAndWait = dProcessID
    32. End Function

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    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
  •  



Click Here to Expand Forum to Full Width