G
Guest
Sample code below:
Dim iRet As Integer
Dim si As New STARTUPINFO
Dim pi As PROCESS_INFORMATION
si.cb = Marshal.SizeOf(si)
iRet = CreateProcessWithLogonW(UserName, DomainName, Password, _
LOGON_WITH_PROFILE, Nothing, CommandLine, _
NORMAL_PRIORITY_CLASS, 0, StartIn, si, pi)
If iRet = 0 Then
Throw New System.ComponentModel.Win32Exception
Else
Try
p = Process.GetProcessById(pi.dwProcessId)
AddHandler p.Exited, AddressOf ProcessExitHandler
p.EnableRaisingEvents = True
Catch ex As ArgumentException
'Process ID no longer exists. Don't worry about it.
End Try
CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)
End If
CreateProcessWithLogonW 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 EnableRaisingEvents
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_INFORMATION
si.cb = Marshal.SizeOf(si)
iRet = CreateProcessWithLogonW(UserName, DomainName, Password, _
LOGON_WITH_PROFILE, Nothing, CommandLine, _
NORMAL_PRIORITY_CLASS, 0, StartIn, si, pi)
If iRet = 0 Then
Throw New System.ComponentModel.Win32Exception
Else
Try
p = Process.GetProcessById(pi.dwProcessId)
AddHandler p.Exited, AddressOf ProcessExitHandler
p.EnableRaisingEvents = True
Catch ex As ArgumentException
'Process ID no longer exists. Don't worry about it.
End Try
CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)
End If
CreateProcessWithLogonW 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 EnableRaisingEvents
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!