how to cancel stating a process when the computer is shutting down?

0

I have a program that uses an external process to complete its work using ProcessName.Start(), the problem is that when windows is shutting down I want to know that it is shutting down before starting the process, because if the application start the process while shutting down windows shows a message that the process was unable to start correctly (ERROR CODE 0xc0000142).

The main Application is a C# Windows forms application with a notification icon, and the external process is a native console application written in old C (and that is for a good reason).

I used some System events like SessionEnding, and overridden the WndProc to handle windows messages but without success, the application receive these events and messages somewhat late and the application would have started the process and the Error message is shown.

I hope someone can help me on this.

Thnx

c#

2 Answers

0

Would it be possible to listen for the SessionEnding event, cancel the event if the secondary process has already started, and then shutdown or log off after the secondary process has completed it's task?

This thread describes various methods of shutting down a computer from C#.

answered on Stack Overflow Mar 27, 2011 by AndrewP • edited May 23, 2017 by Community
0

I have solved my problem by creating a DLL and call it instead of the external process, I tried to create it before but I had some problems and I tried again and it worked.

answered on Stack Overflow Mar 28, 2011 by موسى شاور • edited Oct 9, 2013 by krsteeve

User contributions licensed under CC BY-SA 3.0