3

Possible Duplicate:
How to detect whether Windows is shutting down or restarting

In c# I am able to find only whether windows is logging off or getting shutdown using below code.

SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);

static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
    {

        switch (e.Reason)
        {
            case SessionEndReasons.Logoff:
                break;
            case SessionEndReasons.SystemShutdown:
                break;
            default:
                break;
        }
    }

But I want to know how to capture windows re-start event in c#.?

Community
  • 1
  • 1
Saran
  • 835
  • 3
  • 11
  • 31
  • 2
    I am curious: Why whould that be from interest for a programm to know if a computer is shutdown or rebooted. How would that affect your programm? Even if I choose reboot, I can still cancel the process before windows is loading by just powering of the machine. – Jürgen Steinblock Aug 20 '12 at 09:46
  • Richards , Reading registry and find out whether windows is restarting is look like some work around. I feel there should be some win32 events to find out this. More over I logged in windows using limited user. So I can't read registry settings. – Saran Aug 20 '12 at 10:14
  • SchlaWiener, In my App, I don't want the user to shutdown, But he should be able to re-start, or logoff the machine. – Saran Aug 20 '12 at 10:17
  • 1
    You would do better to do this by policy rather than by your application. – BugFinder Aug 20 '12 at 10:57
  • What's stopping the user from force-quitting your application? I'd go with a more system-managerial process (such as BugFinder's suggestion to use policies). – J. Steen Aug 20 '12 at 11:02
  • So the Answer is , there is no Windows Event to find machine is going to re-started. – Saran Aug 21 '12 at 09:22

0 Answers0