Sample code below:
Dim iRet As Integer
Dim si As New STARTUPINFO
Dim pi As PROCESS_INFORMA TION
si.cb = Marshal.SizeOf( si)
iRet = CreateProcessWi thLogonW(UserNa me, DomainName, Password, _
LOGON_WITH_PROF ILE, Nothing, CommandLine, _
NORMAL_PRIORITY _CLASS, 0, StartIn, si, pi)
If iRet = 0 Then
Throw New System.Componen tModel.Win32Exc eption
Else
Try
p = Process.GetProc essById(pi.dwPr ocessId)
AddHandler p.Exited, AddressOf ProcessExitHand ler
p.EnableRaising Events = True
Catch ex As ArgumentExcepti on
'Process ID no longer exists. Don't worry about it.
End Try
CloseHandle(pi. hThread)
CloseHandle(pi. hProcess)
End If
CreateProcessWi thLogonW is called with credentials for an account belonging
to the Administrators group. The code above is run from a non-administrative
account. The problem is, I cannot get the managed Process class to access
any of the exit information for the process. Setting EnableRaisingEv ents
generates another Win32Exception, as well as calling WaitForExit or checking
the HasExited property of the process class.
Is there any way to check the exit state of the process in this situation?
I have other code that needs to execute, but only after the process has
finished.
Thanks!
Dim iRet As Integer
Dim si As New STARTUPINFO
Dim pi As PROCESS_INFORMA TION
si.cb = Marshal.SizeOf( si)
iRet = CreateProcessWi thLogonW(UserNa me, DomainName, Password, _
LOGON_WITH_PROF ILE, Nothing, CommandLine, _
NORMAL_PRIORITY _CLASS, 0, StartIn, si, pi)
If iRet = 0 Then
Throw New System.Componen tModel.Win32Exc eption
Else
Try
p = Process.GetProc essById(pi.dwPr ocessId)
AddHandler p.Exited, AddressOf ProcessExitHand ler
p.EnableRaising Events = True
Catch ex As ArgumentExcepti on
'Process ID no longer exists. Don't worry about it.
End Try
CloseHandle(pi. hThread)
CloseHandle(pi. hProcess)
End If
CreateProcessWi thLogonW is called with credentials for an account belonging
to the Administrators group. The code above is run from a non-administrative
account. The problem is, I cannot get the managed Process class to access
any of the exit information for the process. Setting EnableRaisingEv ents
generates another Win32Exception, as well as calling WaitForExit or checking
the HasExited property of the process class.
Is there any way to check the exit state of the process in this situation?
I have other code that needs to execute, but only after the process has
finished.
Thanks!
Comment