Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Reboot, restart or logoff system


Declare Function ExitWindowsEx Lib "user32" ( ByVal uFlags As Long , ByVal dwReserved As Long ) As Boolean
Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1

'logoff
Dim iResult As Boolean
If MsgBox( "Are you sure?" , vbOKCancel + vbCritical, "Log off" ) = vbOK Then
   iResult = ExitWindowsEx(EWX_LOGOFF, 0)
    Unload Me
End If

'reboot
Dim iResult As Boolean
If MsgBox( "Are you sure?" , vbOKCancel + vbCritical, "Reboot" ) = vbOK Then
   iResult = ExitWindowsEx(EWX_REBOOT, 0)
    Unload Me
End If

'shutdown
Dim iResult As Boolean
If MsgBox( "Are you sure?" , vbOKCancel + vbCritical, "Shut down" ) = vbOK Then
   iResult = ExitWindowsEx(EWX_SHUTDOWN, 0)
    Unload Me
End If