问题
I'm trying to run an application from our internal website. When I use Process.Start("notepad");
I can see that notepad process started in our web server with default identity mentioned in the app pool setting.
But I have to start the process with specific user name & password. So I have tried to run this line of code
string password = "XXXXX";
System.Security.SecureString securePwd = new System.Security.SecureString();
foreach (char c in password)
{
// Append the character to the password.
securePwd.AppendChar(c);
}
Process.Start("notepad", "username", securePwd, "domain");
In this case I don't even see any notepad process started in the web server. The lines of code executing because when I pass wrong password I can see my webpage throwing error of "bad username or password".
回答1:
Thanks everyone for your reply. Here I got the solution and now my process start with impersonated user.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;889251
Thanks.
回答2:
The code you've written looks fine to me. Perhaps the problem is
I don't even see any notepad process
I would try the following
Capture the ID and write it out to the client e.g.
Process note = Process.Start("notepad", "username", securePwd, "domain");
Response.Write( note.ID ); //Or whatever mechanism you prefer.
Then log on to the server and with PowerShell query the process
e.g.
PS C:\> get-process notepad | Select ProcessName, Id
ProcessName Id
----------- --
notepad 5512
The Id should match what was written to the client
来源:https://stackoverflow.com/questions/6022408/how-to-start-a-iis-process-with-specific-username-password