13

On Windows 8 I am running a windows service. This service is supposed to start a program by

Process.Start(exePath);

But the process exits immediately - even first line in the Main procedure is not executed. Before, when running the same process in same service on Windows 7, everything worked fine.

How can I make it work again? How to properly start a process from a windows service?

frakon
  • 1,948
  • 2
  • 22
  • 26
  • HI, even I am facing the same problem. I am running my windows service on windows 7 system under local system account. The process is not at all starting. Any help would be appreciated. – Arti Jul 07 '14 at 06:40

2 Answers2

17

Found the solution. Process has to be started like this:

ProcessStartInfo info = new ProcessStartInfo(exePath);
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process.Start(info);

For some reason there are problems with priviledges when creating a shell window in the background of the SYSTEM.

frakon
  • 1,948
  • 2
  • 22
  • 26
  • 3
    This is your solution to your problem but hardly the answer to the question that you asked. You provided no real details and then presented an answer that appears to be based on magic. No explanation why. And it was a self-answer Q&A question. How is this going to be useful to anyone in the future? What you could do would be to provide enough information for somebody to reproduce the problem. Then you might get a good answer and gain some understanding. As it stands you are going to be left with this magic incantation. – David Heffernan Mar 24 '14 at 10:22
  • 9
    I searched for the answer, did not find any suitable. Then thanks to link https://groups.google.com/forum/#!msg/comp.windows.misc/E93qPCdaV4k/f1YIwTjwzGcJ I found this solution. It is link about C++ and some unknown library, explanation not very clear, the only (very) usefull thing there was "CREATE_NO_WINDOW" flag, which led me to this solution, which I wanted to share for others, to find it faster. I would appreciate deeper explanation too. – frakon Mar 24 '14 at 13:33
  • You don't understand my point. This might, maybe, be the solution to your problem. But it's not the answer to the question you asked which contained no real actionable detail. How is anyone going to relate this answer to their problem, based on the question that you asked. Perhaps you should improve the question. Otherwise this, in my view, is rather pointless. – David Heffernan Mar 24 '14 at 13:41
  • 10
    Regardless of an explanation the solution helped me get past the same problem. Thanks frakon! – Andrew Brown Jul 05 '16 at 20:04
  • Just like here https://stackoverflow.com/a/27997144/4684145 it fixed my problem to get a 7zip archive decompressed, thnx! – Marco Duindam Apr 23 '20 at 17:49
-3

Use WaitForExit method on your Process instance will instruct to wait until the time elapsed or the process has exited.

See this MSDN link for more.

S.N
  • 4,910
  • 5
  • 31
  • 51