Rohitbd

Hello,

I could not find a suitable category for this query hence I am posting it here.

I want to determine programmatically whether the machine was last shut down normally or not. Basically we have a service which has to detect this when the machine (with Win XP embedded) boots. There are two types of shutdown to be detected:
1. Due to a reset operation. (hardware or software)
2. Due to a power failure. (hardware or software)

Is it possible to do so using .NET (C#)

Any help is greatly appreciated.
Thanks,
Rohit.


Re: Visual C# General Detecting whether the last shutdown was normal or not.

Ernst Kuschke

Have a look at the SystemEvents.SessionEnding event here.

Have your service log the shutdown reason during SessionEnding, and interogate this value during service startup.
(If no log entry exists, the machine was obviously not shutdown properly).