0

How can I control the state of Windows. in Net? Especially interested in how to not let the system go to sleep (if the user for a long time did not use the input devices). How can I track event when the system is going to go into standby, sleep or hibernation because of user inactivity, and cancel it at run time (in some case)? Any information applicable to .Net would be useful.

Thanks in advance.

Kovpaev Alexey
  • 1,725
  • 6
  • 19
  • 38
  • 1
    Look here: http://stackoverflow.com/questions/10052402/preventing-computer-from-sleeping – Adam May 27 '12 at 15:04
  • @Adam, Oh, thank you. I'm more interested in how to react to the attempt of the system to go into standby, sleep or hibernation, and under certain conditions, cancel it (maybe simulate user input). Do you have any idea how to trace the attempt of the system to shut down? – Kovpaev Alexey May 27 '12 at 17:47
  • added an answer. hope it helps... – Adam May 27 '12 at 17:59

2 Answers2

1

Investigate on WMI, Windows Management Instrumentation.

WMI is good for the question because it offers a deep control of the Windows operative system, it has an event system, and it offers a .NET interface.

Indeed WMI allows a .NET application (by using its WMI interface) to be notified about system power events, by this WMI class.

Of course, the Adam comment link shall be taken into account to allow (or not) the system standby.

Community
  • 1
  • 1
Luca
  • 11,646
  • 11
  • 70
  • 125
  • My first answer was composed only by the first line (in my opinion, the answer effort compensate the question effort), but the downvoter didn't tough the same. – Luca May 27 '12 at 21:55
0

In WinForms you can detect shutdown. In FormClosing event you get FormClosingEventArgs e. Then you just check e.CloseReason == CloseReason.WindowsShutDown - this means the reason of closing the form is shutting down of the OS.

Adam
  • 26,549
  • 8
  • 62
  • 79