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...
"Thank You" to anyone replying!!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
nobair




Reply With Quote