0

I have a requirement to check for and start a process if it is not already running on our remote server. The problem I am having is the process starts as a background process, which is not desired. Here is the code I am using to start the process:

public Process StartUploader()
    {
        try
        {
            var uploaderLocation = Properties.Settings.Default.CaptureLifeUploaderLocation;
            var uploadProcess = uploaderLocation + Properties.Settings.Default.CaptureLifeUploaderFilename;

            Logger.Info($"Checking {uploaderLocation} for {Properties.Settings.Default.CaptureLifeUploaderFilename}");

            if (Directory.Exists(uploaderLocation))
            {
                var files = Directory.EnumerateFiles(uploaderLocation).Count();
                if (files > 0)
                {
                    return Process.Start(uploadProcess);
                }
            }

            var errorMessage = $"{uploadProcess} not found. Please check the directory/filename and try again.";
            Logger.Error(errorMessage);
            throw new FileNotFoundException(errorMessage);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }   
    }

When I run this locally, the process in question starts in the foreground as expected. When it is ran on the server, not so much. The AppPool is set to the same Identity as the 'user' on the server that the program is installed under. I have tested this with notepad.exe and have the same issue with that program.

rene
  • 41,474
  • 78
  • 114
  • 152
OCDDev
  • 307
  • 1
  • 2
  • 12
  • 2
    IIS isn't going to be able to do this since it is not running in an interactive session. Only a logged on user with an interactive session will be able to do this. – squillman Feb 22 '16 at 17:52
  • @squillman is there anyway to achieve what I am tying to do via code? – OCDDev Feb 22 '16 at 17:53
  • Just to clarify, you're trying to launch an interactive process on the client's machine right? – squillman Feb 22 '16 at 17:55
  • I am trying to launch a third-party utility in a state where I can verify it has done the work it needs to do. I am assuming this would be the same as an interactive process. I do not actually have to interact with the program other than verifying it is working as expected. Does that answer your question? – OCDDev Feb 22 '16 at 17:57
  • I would look into WMI to manage processes on remote machines : http://stackoverflow.com/a/2343745/3922214 – Jonathan Carroll Feb 22 '16 at 17:58
  • @OCDDev Where do you want to see the third party app? On your machine or on the server? – squillman Feb 22 '16 at 17:59
  • Have a look at this article http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-and-bit-Archite – NineBerry Feb 22 '16 at 18:01
  • @squillman On the server. – OCDDev Feb 22 '16 at 18:04

1 Answers1

0

If the app has a GUI and you want to launch it on the server then someone has to remain logged in on the server so that there is an active session to host / receive the process. This is typically not the desired scenario, but if it's acceptable to you then pursuing something like what NineBerry linked to in comments on the question is the way to go. If you can't leave a user logged in then you will need to find a different solution such as a command-line version of the tool, an API, or logging from the tool.

squillman
  • 13,363
  • 3
  • 41
  • 60