0

I have this code that opens an application:

        string cFilename = "Test.exe";
        string cPath = "C:\\Temp\\";
        System.Diagnostics.Process pStart = new System.Diagnostics.Process();
        pStart.StartInfo.FileName = cFilename;
        pStart.StartInfo.WorkingDirectory = cPath;
        pStart.Start();
        pStart.Dispose();

If I use it in another application all right, if I use it in a service on OnStart (), the application opens but in the background and is not displayed,I only see it in windows processes. What did I do wrong?

Antonio
  • 1
  • 1
  • 1
    Services run in a *different* session to any interactive sessions related to users who have logged in. Session 0 (where services live) isn't associated with a desktop and doesn't show any windows. If you have "service parts" and "interactive parts", you need to move the bits requiring interaction into a separate exe (that probably is set up to run whenever a new login is successful) and use some form of IPC if the two parts need to communicate. – Damien_The_Unbeliever Aug 05 '18 at 08:43
  • 1
    (And then launching any other programs would be done by the interactive parts) – Damien_The_Unbeliever Aug 05 '18 at 08:44
  • If you need something to run continuously within the user's active session (so that it can do things like launch apps), it shouldn't be a service. Have you considered using [Windows Task Scheduler](https://stackoverflow.com/questions/4249542/run-a-task-every-x-minutes-with-windows-task-scheduler)? – John Wu Aug 05 '18 at 08:52
  • @Jhon Wu, I tried but, I do not know why, this does not work, the other task yes. – Antonio Aug 06 '18 at 14:42

1 Answers1

0

Just in case your requirement is to have an app with UI and to hide it when the user clicks the close button on the main window, then you could minimize the app to the system tray. Then have a context menu popup on right clicking the icon on the system tray. In this menu you could have menu items like hide/show/quit etc. And then if you want to start the app as soon as Windows boots up you could add this app to the startup folder.

Check out this SO query

minimize app to system tray

Subbu
  • 588
  • 1
  • 7
  • 18