Using the ExitWindowsEx API call, you can tell windows to shutdown, restart of log off:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As
Long, ByVal dwReserved As Long) As Long
Private Const EWX_FORCE = 4
Private Const EWX_LOGOFF = 0
Private Const EWX_REBOOT = 2
Private Const EWX_SHUTDOWN = 1
Private Sub cmdShutDown()
ExitWindowsEx EWX_SHUTDOWN, 0
End Sub
You can also make the PC log off, reboot or force a log off (without giving the user a chance to save his/her files), by using the other constants instead of EWX_SHUTDOWN. Note that in Windows 2000 (maybe NT 4 too), EWX_SHUTDOWN and EWX_REBOOT do not work. I presume this is a security measure so that virus writers cannot turn of a critical PC. EWX_LOGOFF and EWX_FORCE still work.
Comments