Well, PSTools is the easy way to do it, but for those of us who prefer
to roll their own, here's a vbscript that will do the same thing. I
like something that I can customize.
Be aware that regardless of which way you do it, either psshutdown or a
script, both of them use the "force" option which closes all open
programs without saving files, so don't use them unless you are sure
that nothing will be lost.
This is where a script can come in handy. The script below is pretty
basic, but can be modified to search through running processes on the
remote computer for critical ones and can take steps to abort or save
files as appropriate.
'========================================================
Dim strComputer, strAction, nAction, oLocator, oConnection, oWindows, oSys
If WScript.Arguments.count = 2 Then
strComputer = UCase(WScript.Arguments(0))
strAction = UCase(WScript.Arguments(1))
Else
WScript.Echo "restart.vbs strComputer strAction (REBOOT, LOGOUT, SHUTDOWN)"
WScript.Quit
End If
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
Select Case strAction
Case "REBOOT": nAction = EWX_REBOOT + EWX_FORCE
Case "LOGOUT": nAction = EWX_LOGOFF + EWX_FORCE
Case "SHUTDOWN": nAction = EWX_POWEROFF + EWX_FORCE
Case Else
WScript.Quit
End Select
Set oLocator = CreateObject("WbemScripting.SWbemLocator")
Set oConnection = oLocator.ConnectServer(strComputer,"root\cimv2")
Set oWindows = oConnection.ExecQuery("Select Name From Win32_OperatingSystem")
For Each oSys In oWindows
oSys.Win32ShutDown(nAction)
Next
'========================================================
Just save it as restart.vbs and run it as a custom command like this:
restart.vbs %HOST% LOGOUT
You can also make it a remote script by removing all the lines before the first CONST line and replacing them with:
strComputer = "."
strAction = "LOGOUT"
--Alan--