Re: remote shutdown, not logged in
From: Torgeir Bakken (MVP) (Torgeir.Bakken-spam@hydro.com)
Date: 02/09/03
- Next message: Tim Morton: "moved files from FAT32 lost"
- Previous message: Chuck: "Office 97"
- In reply to: Steve O'Brien: "remote shutdown, not logged in"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> Date: Sun, 09 Feb 2003 20:19:42 +0100
Steve O'Brien wrote:
> Hi,
>
> We're using a whole bunch of XP clients at our
> organization (using SP1, all the critical updates
> available as of right now). Instead of going around at
> night, we'd like to shut them all down remotely.
>
> I tried:
>
> shutdown -s -m \\pc19
>
> This works when a user (guest, admin, etc) is logged in
> at the console. When the login screen is up, this
> command doesn't work. I'm logged on interactively at the
> machine from which I'm running the remote shutdown
> command, as a domain administrator. I'm not having an
> access denied issue - the error returned is "the device
> is not ready".
Hi
Using VBScript/WMI may work better. Put the following code into a file called
e.g. shutdwn.vbs. If you run it without any input arguments, it will do a forced
power off the local computer. If you add one or more remote computer names/ip
addresses on the command line, the script will do a forced power off on the
remote computer(s). See further down in the script for more shutdown/reboot
options.
Set oArgs = WScript.Arguments
If oArgs.Count = 0 Then
' local computer
ShutDown ".", "PowerOff_Force"
Else
For i = 0 to oArgs.Count - 1
ShutDown oArgs(i), "PowerOff_Force"
Next
End If
' Use "PowerOff" for a poweroff
' Use "PowerOff_Force" for a forced poweroff
' Use "Shutdown" for a shutdown
' Use "Shutdown_Force" for a forced shutdown
' Use "Reboot" for a reboot
' Use "Reboot_Force" for a forced reboot
' Use "LogOff" for a logoff
' Use "LogOff_Force" for a forced logoff
' use "." for local computer
Sub ShutDown(sNode, sAction)
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
On Error Resume Next
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" _
& sNode & "\root\cimv2")
Set colOperatingSystems = oWMI.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each obj in colOperatingSystems
Set oOS = obj : Exit For
Next
If Err.Number <> 0 Then
WScript.Echo "Could not connect to " & sNode
Exit Sub
End If
sAction = LCase(sAction)
Select Case sAction
Case "logoff"
iCmd = EWX_LOGOFF
Case "logoff_force"
iCmd = EWX_LOGOFF + EWX_FORCE
Case "shutdown"
iCmd = EWX_SHUTDOWN
Case "shutdown_force"
iCmd = EWX_SHUTDOWN + EWX_FORCE
Case "reboot"
iCmd = EWX_REBOOT
Case "reboot_force"
iCmd = EWX_REBOOT + EWX_FORCE
Case "poweroff"
iCmd = EWX_POWEROFF
Case "poweroff_force"
iCmd = EWX_POWEROFF + EWX_FORCE
Case Else
' Default value
iCmd = EWX_POWEROFF
End Select
oOS.Win32shutdown iCmd
End Sub
-- torgeir Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and a ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter
- Next message: Tim Morton: "moved files from FAT32 lost"
- Previous message: Chuck: "Office 97"
- In reply to: Steve O'Brien: "remote shutdown, not logged in"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|