I see a lot of posts in newsgroups requesting how to reboot Windows using VB. To do that you can use the ExitWindowsEX Function. But there is also a ExitWindows function and because of that, I always see posts asking what the difference is between the two.
ExitWindows - will force a log off of current user.
ExitWIndowsEx - Can logoff, shutdown, powerdown, or reboot and Force A shutdown (closing all open applications without notice).
Public Declare Function ExitWindows Lib "user32" Alias "ExitWindows" (ByVal dwReserved As Long, ByVal uReturnCode As Long) As Long Private Sub Command1_Click() Dim lreturn As Long lreturn=ExitWindows(0,0) End Sub
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As _
Long, ByVal dwReserved As Long) As Long
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Private Sub Command1_Click()
Dim Msg As VbMsgBoxResult
Dim ret
Msg = MsgBox("This program will restart your computer!" + vbCrLf + _
"Are you sure you want to proceed ?", vbCritical + vbYesNo)
If Msg = vbNo Then Exit Sub
ret& = ExitWindowsEx(EWX_REBOOT, 0)
End Sub