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

2 Answers2

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#.

Community
  • 1
  • 1
AndrewP
  • 49
  • 6
  • Thnx for your response. but my problem is that I want to cancel calling the process when system is shutting down not delaying the shutdown process – موسى شاور Mar 28 '11 at 10:00
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.

krsteeve
  • 1,794
  • 4
  • 19
  • 29