Hello again...
I have some VBA code that is doing a shell-and-wait on an executable being launched by wscript. I originally setup the code using a mapped network drive letter, but after switching it to the UNC version, error traps kick in while trying to run the shell command. I've been debugging and get 100% correct results when using mapped network drives to a file share location, but get disperate results otherwise. Is this process access rights related? This isnt my area at all.
Public Function ShellAndWait(ByVal szCommandLine As String, ByVal fldr_name As String, Optional ByVal iWindowState As Integer = vbHide) As Boolean
Dim lTaskID As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim lResult As Long
' gszErrMsg As String is declared globally above
On Error GoTo ErrorHandler
ShellAndWait = True
''' Run the Shell function.
lTaskID = Shell(szCommandLine, vbHide)
''' Check for errors.
If lTaskID = 0 Then Err.Raise 9999, , "Shell function error."
''' Get the process handle from the task ID returned by Shell.
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID) --> this is where errors occur. All three arguments seems to accept the data being passed, but something is killing it.
''' Check for errors.
If lProcess = 0 Then Err.Raise 9999, , "Unable to open Shell process handle." --> this error is thrown each time a UNC path is used
''' Loop while the shelled process is still running.
Do
''' lExitCode will be set to STILL_ACTIVE as long as the shelled process is running.
lResult = GetExitCodeProcess(lProcess, lExitCode)
DoEvents
Loop While lExitCode = STILL_ACTIVE
ShellAndWait = True
End Select
Exit Function
ErrorHandler:
gszErrMsg = Err.Description
ShellAndWait = False
End Function
I need to use PROCESS_QUERY_INFORMATION to watch the exit code. I tried PROCESS_QUERY_LIMITED_INFORMATION as well, but the results were the same. If anything sticks out, please let me know. I will continue to dig on my end.
Thanks forumers...
Bookmarks