Results 1 to 4 of 4

Thread: WaitForSingleObject & ShellExecuteEx together

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    IL, USA
    Posts
    17

    Angry WaitForSingleObject & ShellExecuteEx together

    I had developed an application that would launch another using the ShellExecuteEx call and then wait for that app to finish using the WaitForSingleObject call. This seemed to work OK on NT 4.0 but when they upgraded me to W2K it doesn't wait until the shelled app finishes before returning the signaled state.

    Is this a W2K problem or is using this combonation less reliable than using the CreateProcess call?

    I used the ShellExecuteEx call because of the error reporting capabilities, does the CreateProcess have the same error reporting capabilities?

    Here is some code...

    Code:
    With ShellInfo
            ' Size of the structure
            .cbSize = Len(ShellInfo)
            ' Use the optional hProcess element of the structure.
            .fMask = SEE_MASK_NOCLOSEPROCESS & SEE_MASK_FLAG_NO_UI
            ' Handle to the window calling this function.
            .hwnd = Me.hwnd
            ' The action to perform: open the file.
            .lpVerb = "open"
            ' The file to open.
            .lpFile = RunningJob
            ' Application arguments.
            .lpParameters = Args
            ' The default directory -- not really necessary in this case.
            .lpDirectory = ""
            ' Window display.
            .nShow = SW_HIDE
            ' The other elements of the structure are either not used
            ' or will be set when the function returns.
    End With
    
    'Open the file using its associated program.
    retval = ShellExecuteEx(ShellInfo)
    
    'if retval is 0 we have a problem...
    If retval = 0 Then
            ' The function failed, so report the error.
            Select Case ShellInfo.hInstApp
                Case SE_ERR_FNF
                    MsgBox "The file " & RunningJob & " was not found. Check the file location for errors." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - File Not Found: " & RunningJob
    
                Case SE_ERR_ACCESSDENIED
                    MsgBox "The system has denied access to the file " & GetJobPath(RunningJobNum) & ". Check that the file has proper user permissions and is not already running." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - Access to " & RunningJob & " Denied"
    
                Case SE_ERR_PNF
                    MsgBox "The file path for " & GetJobPath(RunningJobNum) & " was not found. Check the file location for errors." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - File Path Not Found: " & RunningJob
    
                Case SE_ERR_OOM
                    MsgBox "This system is out of memory and cannot execute the job '" & GetJobPath(RunningJobNum) & ". Check the system's performance and free up any unnecessary resources." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - System Out Of Memory"
    
                Case SE_ERR_DLLNOTFOUND
                    MsgBox "A required .dll file could not be found to start '" & GetJobPath(RunningJobNum) & "'. Check that all necessary files are available." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - DLL Not Found"
    
                Case SE_ERR_SHARE
                    MsgBox "A shared file could not be found to start '" & GetJobPath(RunningJobNum) & "'. Check that all necessary files are available." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - Shared File Not Found"
    
                Case Else
                    MsgBox "An error occured while trying to start '" & GetJobPath(RunningJobNum) & "'. Check that all necessary files are available." & vbCr & vbCr & "The Batch log has been noted.", vbMsgBoxSetForeground + vbCritical, "ATS Batch Manager - Error Executing '" & RunningJob & "'"
    
            End Select
    Else 'retval is not zero - success!
    
            'Wait for job to finish
            Do
                frmControlJobs.Label4.ToolTipText = "Current execution time: " & CInt(Timer - RunTime) & " seconds."
                Label2.ToolTipText = "Current execution time: " & CInt(Timer - RunTime) & " seconds."
                
                DoEvents
                
                'Check to see if the running job has finished
                retval = WaitForSingleObject(ShellInfo.hProcess, 0)
                
                temmp = temmp + 1
            Loop While retval = WAIT_TIMEOUT
    
            Report = "The job '" & GetJobPath(RunningJobNum) & " ' executed successfully."
            RunStatus = "Successfull"
    
    End If
    "Thank You" to anyone replying!!

    nobair

  2. #2
    jim mcnamara
    Guest
    This method seems to work on all OS plaforms we've tried.
    It's CreateProcess & WaitForSingleObject

    http://www.vbforums.com/showthread.p...orsingleobject

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    IL, USA
    Posts
    17

    Question Need more info...

    Jim,

    I would like to try using the CreateProcess function but I can not find a good reference containing info on the two type declares used in the example and info on the constants and error handling for CreateProcess (the error constants are important because I need to know why a process failed). I really like the style of the www.vbapi.com website, but it doesn't list any of the types in the example and doesn't include the CreateProcess function. I know I have seen something close to this on microsoft's site somewhere, but I can't find it.

    Do you know where that is on the M$ site or do you know of any online reference that gives explanations and examples of the CreateProcess function like the vbapi.com site?

    nobair

  4. #4
    jim mcnamara
    Guest
    Here is sample code witht the structs (UDT's) for CreateProcess.

    http://www.allapi.net/apilist/exampl...=Super%20Shell

    While you're at allapi.net, consider dopwnloading the Api-Guide & Toolshed. The Guide is examples and explanations, the Toolshed is all of the the Declares, Types & Constants.

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