Process.Start()模拟问题

尝试使用另一个访问令牌启动进程,但没有成功,它作为非模拟用户运行。

using (WindowsIdentity identity = new WindowsIdentity(token)) using (identity.Impersonate()) { Process.Start("blabla.txt"); } 

如何使这项工作正常?

您需要设置ProcessStartInfo.UserName和Password属性。 将UseShellExecute设置为false。 如果您只有令牌,则请调用CreateProcessAsUser()。

从http://msdn.microsoft.com/en-us/library/w070t6ka.aspx试试此示例

 private static void ImpersonateIdentity(IntPtr logonToken) { // Retrieve the Windows identity using the specified token. WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken); // Create a WindowsImpersonationContext object by impersonating the // Windows identity. WindowsImpersonationContext impersonationContext = windowsIdentity.Impersonate(); Console.WriteLine("Name of the identity after impersonation: " + WindowsIdentity.GetCurrent().Name + "."); //Start your process here Process.Start("blabla.txt"); Console.WriteLine(windowsIdentity.ImpersonationLevel); // Stop impersonating the user. impersonationContext.Undo(); // Check the identity name. Console.Write("Name of the identity after performing an Undo on the"); Console.WriteLine(" impersonation: " + WindowsIdentity.GetCurrent().Name); } 

您还可以使用CreateProcessAsUser窗口函数。

http://www.pinvoke.net/default.aspx/advapi32/createprocessasuser.html