Programming » Visual Basic 6 » Visual Basic 6 Code » Windows API » ");?>
Restart windows, shut the computer down or logoff the user programmatically.
' If the function returns you can assume that another application refused
' to terminate. The EWX_FORCE option can be used to attempt to force the
' issue.

Const EWX_FORCE = 4
Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_SHUTDOWN = 1
Declare Function ExitWindowsEx Lib "user32" _
        (ByVal uFlags As LongByVal dwReserved As LongAs Long

Function RestartWindows() As Boolean
    RestartWindows = CBool(ExitWindowsEx(EWX_REBOOT, 0))
End Function

Function ShutDownPC() As Boolean
    ShutDownPC = CBool(ExitWindowsEx(EWX_SHUTDOWN, 0))
End Function

Function LogOffPC() As Boolean
    ShutDownPC = CBool(ExitWindowsEx(EWX_LOGOFF, 0))
End Function