0

Given the following launch method:

public static int LaunchExternalApplication(string application, string arguments, string workingDirectory, bool isFireAndForget)
    {
        //Check all required parameters are present
        if (string.IsNullOrEmpty(application))
        {
            throw new Exception("Application Path missing");
        }

        int applicationStatus = -1; //-1 indicates failure
        Process launchApplicationProcess = new Process();

        try
        {
            launchApplicationProcess.StartInfo.FileName = application;
            launchApplicationProcess.StartInfo.Arguments = arguments;

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                launchApplicationProcess.StartInfo.WorkingDirectory = workingDirectory;
            }

            applicationStatus = (launchApplicationProcess.Start() ? 0 : -1);
            Int32 pid = (!launchApplicationProcess.HasExited) ? launchApplicationProcess.Id : 0;

            // only check in on the Process if we care...
            if (!isFireAndForget)
            {
                launchApplicationProcess.WaitForInputIdle(10000); // wait for the window to display
                launchApplicationProcess.WaitForExit(); // wait for the application to do it's thing before exiting
                applicationStatus = launchApplicationProcess.ExitCode; // Get the exitcode for the application to determine if it was successful or not.
            }

        }
        catch (Exception except)
        {
            throw new Exception("An unexpected exception occurred while launching application", except);
        }
        finally
        {
            launchApplicationProcess.Dispose();
        }

        return applicationStatus;
    }

Just as an example I pass in the application path to NotePad "C:\Windows\system32\notepad.exe" I would expect when it hits the line

applicationStatus = (launchApplicationProcess.Start() ? 0 : -1);

Notepad would get launched, but this is not the case, the process for it is started but the application is not launched. I'm unsure what is at fault here as this will run fine when hosted in a console app and not a windows service. Can anyone guide me in the right direction on what to look for?

RichardMc
  • 844
  • 1
  • 9
  • 33
  • 2
    http://blogs.windows.com/windows/archive/b/developers/archive/2009/10/01/session-0-isolation.aspx – Matt Davis Jul 08 '14 at 13:58
  • @Matt Davis, Hmmm did not know about this. I'm almost positive that must be the issue. Thanks for the quick reply. – RichardMc Jul 08 '14 at 14:05

0 Answers0