简体   繁体   中英

How to start a IIS process with specific username & password

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".

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.

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 eg

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

eg

PS C:\> get-process notepad  | Select ProcessName, Id 
ProcessName                                                                  Id
-----------                                                                  --
notepad                                                                    5512

The Id should match what was written to the client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM