简体   繁体   中英

How can I control the state of Windows in .net?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM