0

I'm developing a windows service that monitors the message queue(RabbitMQ). Whenever a message queued up in the message queue, an event will be fired in the windows service and a windows forms application will be launched which takes queue's message as command-line arguments.

All the coding part is fine. On debug mode, I've verified if the event is firing when a message is found in the queue or not, and yes it does hit the event callback. But i don't see the windows form popping up when the event is fired. Below is how i'm trying to execute the windows form.

Process process = new Process();
process.EnableRaisingEvents = true;
process.Exited+= <exit event handler>
process.Start(new ProcessStartInfo(){
       CreateNoWindow=true,
       UseShellExecute=false,
       ErrorDialog=true,
       FileName = "<path to the .exe file of windows form>",
       WindowStyle=ProcessWindowStyle.Hidden
});
process.WaitForExit();

I don't even see any error throwing or logged in EventViewer. Any help in this regard is apprecaited.

Praveen
  • 167
  • 4
  • 13
  • as a norm services do not get to interact with the desktop as they are ru at a level where the UI is not available – BugFinder May 14 '18 at 07:46
  • What exactly is the problem starting a process from within a service? Maybe just the Windowstyle should not be 'Hidden' – nabuchodonossor May 14 '18 at 09:15
  • @nabuchodonossor i tried that as well, but still no luck. All i need is to launch a GUI application from a windows service. – Praveen May 14 '18 at 09:19
  • @praveen: I just learned, that the restriction of user interaction includes programs to start. I assume you have to do some tricks. Mabe it is possible for you to write to an event log, if so, you can trigger an application start. – nabuchodonossor May 14 '18 at 10:17

1 Answers1

1

Ever since Windows Vista, Windows Services are barred from interacting with the Desktop. They are simply not given a interactive session. While you can override that during service registering, it is not something you should seriously consider. The option might entirely vanish soon. I do not even know if it is still there in Windows 10.

They can still launch Interactive Porgramms using the right tricks inlcuding a proper Manifest on the Subprogramm. But communication has then go through IPC. Maybe you could adapt a single instance approach as well, but those are a bit dated nowadays.

Christopher
  • 9,634
  • 2
  • 17
  • 31