Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start does not work when called from windows service

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?

like image 808
frakon Avatar asked Mar 24 '14 10:03

frakon


People also ask

Can a Windows Service start a process?

Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop. This leaves no place for the application to be run.

How do I start a process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.


1 Answers

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.

like image 145
frakon Avatar answered Sep 16 '22 19:09

frakon