5

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

Mo Patel
  • 2,321
  • 4
  • 22
  • 37
Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49

2 Answers2

4

Thanks everyone for your reply. Here I got the solution and now my process start with impersonated user.

https://learn.microsoft.com/en-US/troubleshoot/aspnet/spawn-process-under-impersonated-user

Thanks.

Andrey Shchekin
  • 21,101
  • 19
  • 94
  • 162
Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49
0

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

Conrad Frix
  • 51,984
  • 12
  • 96
  • 155
  • Thanks for replying. I have captured process ID and print it in label control. Every time I execute that process I can see a new process ID. But when I go to power shell and search for that process it gives me error " Get-Process : Cannot find a process with the name "notepad". Verify the process name and call the cmdlet again." – Pritam Karmakar May 16 '11 at 20:25
  • @Pritam Karmakar. That's weird. That means that the process got created but was destroyed before the powershell call. – Conrad Frix May 16 '11 at 20:42
  • Its really very weird behavior. Is there any other way to run application with specific user name? – Pritam Karmakar May 16 '11 at 22:28