PC Review


Reply
Thread Tools Rate Thread

CreateProcessWithLogon and managed Processes

 
 
=?Utf-8?B?RXJpYyBMaXZpbmdzdG9u?=
Guest
Posts: n/a
 
      15th Sep 2005
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!
 
Reply With Quote
 
 
 
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      16th Sep 2005
Hi

What is the concret win32exception do you get?

Is it similar with below?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ComponentModel.Win32Exception: Access is denied


If so I think it is because the user accout did not have the enough
privilegeto open the process.
In the underlying level, the Process class will try to call the OpenProcess
API so that it can monitor the Process status.

You can look into the OpenProcess API in MSDN.
Remarks
To open a handle to another another process and obtain full access rights,
you must enable the SeDebugPrivilege privilege. For more information, see
Changing Privileges in a Token.

The handle returned by the OpenProcess function can be used in any function
that requires a handle to a process, such as the wait functions, provided
the appropriate access rights were requested.

When you are finished with the handle, be sure to close it using the
CloseHandle function.

I think you may try to Impersonalte the administrator account to do the
privilege job.
319615 PRB: "Unable to Impersonate User" Error Message When You Use
http://support.microsoft.com/?id=319615

248187 How to impersonate a user from Active Server Pages
http://support.microsoft.com/?id=248187


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
=?Utf-8?B?RXJpYyBMaXZpbmdzdG9u?=
Guest
Posts: n/a
 
      16th Sep 2005
I also managed to get it to work as needed by calling the native
WaitForSingleObject using the process handle. This caused my current thread
to wait until the process had completed, then I was able to fire an event
after that call to do what I need.

Thanks for the help!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Application failed to intialize" with CreateProcessWithLogon =?Utf-8?B?U3RldmU0RA==?= Microsoft C# .NET 6 13th Apr 2006 03:33 PM
Debugging two processes question/launching two debug processes =?Utf-8?B?bTExNTMz?= Microsoft C# .NET 4 4th Nov 2004 11:57 PM
CreateProcessWithLogon\AdjustTokenPrivileges on Win2K Vincent Finn Microsoft Dot NET 4 30th Jun 2004 12:13 PM
CreateProcessWithLogon on Win2000 Vincent Finn Microsoft VB .NET 0 18th Jun 2004 04:36 PM
CreateProcessWithLogon Vs Runas patanish Microsoft Windows 2000 Developer 1 21st May 2004 08:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.