Get Sleep/Hibernate and Resume/Wakeup events in Visual Basic.NET

ε祈祈猫儿з 提交于 2019-12-03 07:24:40

If your application is using a window and can read the message loop you can simply subscribe to Microsoft.Win32.SystemEvents.PowerModeChanged like:

AddHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged

Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)

    Select Case e.Mode
        Case PowerModes.Resume
        Case PowerModes.StatusChange
        Case PowerModes.Suspend
    End Select

End Sub

Else, if you are using a service for example, you have to create a hidden form like described here (scroll down to 'Example 2')

joey

try below:

To restart the pc

System.Diagnostics.Process.Start("Shutdown", " -r -t 00")

To shutdown the pc

System.Diagnostics.Process.Start("Shutdown", " -s -t 00")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!