4

I'm unable to use Process.Start to start a simple console application when I specify user credentials. It appears that the call to Process.Start tries to start the application, but the application immediately fails with an event log entry (see below). I'm running IIS 7.5/.NET 4.0 on a Windows 7 Ultimate (x64) machine. Application pool runs under ApplicationPoolIdentity and uses Integrated Mode. Web site is set to run under Full Trust.

To test, I created a simple console application, ConsoleApplication1, that simply writes "Hello World" to the console and appends the current date and time to a text file, just so I can see that the application executed. When I run the application from a button click in my ASP.NET app using the following code, I see a new value get written into my text file, as expected.

protected void btnStart_Click(object sender, EventArgs e)
{
    Process.Start(@"C:\dump\test\ConsoleApplication1.exe");
}

When I try to specify a set of user credentials to run the application using the code below, nothing is written to my text file, and I see a message in the Event Viewer that states:

Application popup: ConsoleApplication1.exe - Application Error : The application was unable to start correctly (0xc0000142). Click OK to close the application.

Here is the code that causes the error:

protected void btnStart_Click(object sender, EventArgs e)
{
    Process.Start(@"C:\dump\test\ConsoleApplication1.exe",
        "myusername", CreatePassword("mypassword"), string.Empty);
}

private static SecureString CreatePassword(IEnumerable<char> password)
{
    var ss = new SecureString();
    foreach (var c in password)
        ss.AppendChar(c);
    return ss;
}

I'm pretty sure the authentication of the user credentials is working properly, because I get a Logon failure: unknown user name or bad password error if I enter incorrect info.

I feel like I must be missing something simple, but can anyone point me in the right direction here?

rsbarro
  • 27,021
  • 9
  • 71
  • 75
  • Did you try passing the password in cleartext? – mithun_daa Nov 14 '11 at 22:33
  • What do you mean? To set the password parameter in the call to Process.Start, you have to pass in an instance of SecureString. – rsbarro Nov 15 '11 at 03:37
  • 2
    Basically the same question here: http://stackoverflow.com/questions/6022408/how-to-start-a-iis-process-with-specific-username-password Hard to believe it's really not possible to do this with `Process.Start`. – rsbarro Nov 17 '11 at 06:33
  • The solution at http://stackoverflow.com/questions/677874/starting-a-process-with-credentials-from-a-windows-service worked for me (same problem). – DWright Jan 19 '17 at 23:58

0 Answers0