How do we know when Windows goes to Standby mode?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm developing VB .NET framework. I would like to know how do I know when Windows goes to Standby or Shutdown mode

Thanks
KPH
 
Hi,

From you description, do you want to get notified when user is suspending
or shuting down the system?

For suspending, you may handle the SystemEvents.PowerModeChanged Event.
<SystemEvents.PowerModeChanged Event>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfmicrosoftwin32systemeventsclasspowermodechangedtopic.asp

For Shutdown event , you may handle the SystemEvents.SessionEnded Event
the Reason property in the args will tell you it's raised by a logoff or
shutdown command.
<SystemEvents.SessionEnded Event>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfmicrosoftwin32systemeventsclasssessionendedtopic.asp

Do these two events resolve your problem?
Please feel free to reply this thread if you have anything unclear about
this issue.
Thanks!



Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Hi

How about command set the OS to Shutdown, Standby, Logoff, Hibernate and Restart mode. Did you know that

Thank you
KPH
 
Hi,

Well, this is a different question to how to know the system status.
From Windows 2000, there is an API SetSuspendState which enable you switch
the system into Standby or Hibernate state, for more information you may
referr to
<SetSuspendState>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/
setsuspendstate.asp

For how to shutdown/Logoff the system, you may use API
ExitWindows/ExitWindowsEx, however On windows 2000 and later system, if you
want to log off /Shut down/reboot the system, your program need get the a
special privilege before calling this API. For more information you may
referr to
<ExitWindowsEx>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/bas
e/exitwindowsex.asp
There is also a sample to show you how to shutdown the system, however it's
written in C++.

Unfortunately, these APIs is not included in current release of .NET
Framework. You need use them by P/Invoke. There is an sample project on
CodeProject.com
Maybe you can take reference from it.
<Timer Computer Shutdown>
http://www.codeproject.com/csharp/timercomputershutdown.asp


Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Hi

Since I handle SessionEnded event, sometimes I shutdown my machine It cannot shutdown [ restart or logoff] my machine. After I found this situation I add code to exit program [Form.Close()] when event invoked

What's important point of SessionEnded event, do I need to close my program when event occur

KP
 
Hi,

I'm not clear about that, I found the document of SessionEnding event
mentioned that there is no promise that Form.Closing event will be fired
before SessionEnding event fires, and suggests trap WM_QUERYENDSESSION to
perform some special tasks by overriding the WndProc method, will it do
help for your problem?

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top