MaxOvrdrv
MaxOvrdrv

Reputation: 1916

Process.Start won't work

I am trying to launch a process from a web page's back-end code/app pool. This process will launch an App that i built myself.

For some reason, the process only works / runs when i start it from VS2013... it never works when i launch it from IIS(7.5) itself.

I am on a Windows 7 machine (both IIS host, and App location), and I've setup my web site to only be accessible via internal network.

Here's the code, followed by the config / attempts to fix the issue:

protected void btn_DoIt_Click(object sender, EventArgs e)
{
    string file_text = this.txt_Urls.Text;

    if (!String.IsNullOrWhiteSpace(file_text))
        File.WriteAllText(ConfigurationManager.AppSettings["filePath"], file_text);

    ProcessStartInfo inf = new ProcessStartInfo();

    SecureString ss = GetSecureString("SomePassword");
    inf.FileName = @"........\bin\Release\SomeExecutable.exe";
    inf.Arguments = ConfigurationManager.AppSettings["filePath"];
    inf.UserName = "SomeUserName";
    inf.Password = ss;
    inf.UseShellExecute = false;
    //launch desktop app, but don't close it in case we want to see the results!
    try
    {
        Process.Start(inf);
    }
    catch(Exception ex)
    {
        this.txt_Urls.Text = ex.Message;
    }

    this.txt_Urls.Enabled = false;
    this.btn_DoIt.Enabled = false;
    this.txt_Urls.Text = "Entries received and process started. Check local machine for status update, or use refresh below.";
}

Here are the things I've tried to resolve the issue:

  1. Made sure the executing assembly was built with AnyCPU instead of x86
  2. Ensured that the AppPool that runs the app, also runs under the same account (SomeUsername) as the ProcessStartInfo specified.
  3. Ensured that the specific user account has full access to the executable's folder.
  4. Ensured that IIS_USR has full access to the executable's folder.
  5. Restarted both the app pool and IIS itself many times over implementing these fixes

I am now at a loss as to why this simply will not launch the app... when i first looked into the event log, i saw that the app would die immediately with code 1000:KERNELBASE.dll, which got me on the AnyCPU config instead of X86 fix... that fixed the event log entries but the app still doesn't start (nothing comes up in task manager), and i get no errors in the event log...

if someone could help me fix this problem i would really appreciate it. This would allow me to perform specific tasks on my main computer from any device on my network (phone, tablet, laptop, etc etc) without having to be in front of my main PC...

UPDATE

The comment to my OP, and ultimate answer from @Bradley Uffner actually nailed the problem on the head: My "app" is actually a desktop application with a UI, and in order to run that application, IIS would need to be able to get access to the desktop and the UI, just like if it were a person sitting down in front of the PC. This of course is not the case since IIS is running only as a service account and it makes sense that it shouldn't be launching UI programs in the background. Also see his answer for one way of getting around this.

Upvotes: 0

Views: 2902

Answers (2)

Peter Kiss
Peter Kiss

Reputation: 9319

You should assign a technical user with enough high priviliges to the running application pool. By default the application pool is running with ApplicationPoolIdentity identy which has a very low priviliges.

Upvotes: 0

Bradley Uffner
Bradley Uffner

Reputation: 16991

Your best bet might be to try writing this as 2 parts. A web site that posts commands to a text file (or database, or some other persistent storage), and a desktop application that periodically polls that file (database, etc) for changes and executes those commands. You could write out the entire command line, including exe path command arguments, and switches.

This is the only way I can really think of to allow a service application like IIS to execute applications that require a desktop context with a logged in user.

Upvotes: 3

Related Questions