The Code
Just type the following script into Notepad (with Word Wrap disabled) and
save it with a .vbs extension as
LogoffIcon.vbs:
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}" & _
"//./root/cimv2").ExecQuery("SELECT * FROM " & _
"Win32_OperatingSystem WHERE Primary = true")
ianswer = MsgBox("Did you save your data first?"+vbLf++vbLf+ " LOGOFF?", _
vbCritical + vbYesNo, _
"Logoff?")
If ianswer = vbYes Then 'If OK, shut down
For Each OpSys In OpSysSet
outParam = OpSys.Reboot
If err.number <> 0 Then
WScript.echo "Error number: " & Err.Number & _
vbNewLine & _
"Description: " & Err.Description
End If
Next
Else ' user selected cancel
MsgBox "Logoff Aborted", , "Logoff Aborted"
End If
Copy the script to a folder on the user's machine
and create a shortcut to the folder on his desktop. Then, when the
user needs to reboot his machine, he can double-click on the shortcut
and a dialog box (see ) will suggest that
he save his work before logging off.
Figure 1. Logging off and rebooting
Once he saves his work and clicks OK, he is logged off and his
computer shuts down and restarts.
—Chuck Young