简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM