Hello. I am currently creating a new process from within my vb app using CreateProcessWithLogonW. This command runs another vb app that i created and waits for it to finish. I would like to know how I can get the return code from that child process after it finishes?
The process it calls, returns values using "ExitProcess errornum", and I can't figure out how to get that value back to the calling app.
Thank you. Any help is appreciated.
Here is the funtion I'm using to run the process:
Code:Public Function W2KRunAsUser(ByVal UserName As String, _ ByVal Password As String, _ ByVal DomainName As String, _ ByVal CommandLine As String, _ ByVal CurrentDirectory As String) As Long Dim si As STARTUPINFO Dim pi As PROCESS_INFORMATION Dim wUser As String Dim wDomain As String Dim wPassword As String Dim wCommandLine As String Dim wCurrentDir As String Dim Result As Long Dim lRunas As Long si.cb = Len(si) wUser = StrConv(UserName + Chr$(0), vbUnicode) wDomain = StrConv(DomainName + Chr$(0), vbUnicode) wPassword = StrConv(Password + Chr$(0), vbUnicode) wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode) wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode) Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, _ LOGON_WITH_PROFILE, 0&, wCommandLine, _ CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi) DoEvents Do 'Check every 2 seconds to see if process is done lRunas = WaitForSingleObject(pi.hProcess, 250) DoEvents Loop Until (lRunas = 0 Or lRunas = -1) If Result <> 0 Then CloseHandle pi.hThread CloseHandle pi.hProcess W2KRunAsUser = 0 Else W2KRunAsUser = Err.LastDllError MsgBox "CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation End If End Function


Reply With Quote


Bookmarks