Re: Shutdown remote server

From: Stew Basterash (stewartbash_at_hotmail.com)
Date: 06/12/04


Date: Sat, 12 Jun 2004 16:11:40 -0500

WOW... does everyone do things the hard way...

If you are running Windows XP... try typing "shutdown" at a command
prompt... it will tell you how to remotely shutdown another NT based
system...

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:OLQkdMaTEHA.1988@TK2MSFTNGP12.phx.gbl...
> Paul E. Surette wrote:
> > How can I do a clean shut down of a remote server with VBScript?
> Hi
>
> Alt. 1
>
> PsShutdown.exe in the free PsTools suite (command line)
> http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
>
>
> Alt. 2
>
> Using VBScript/WMI usually works very well also. WMI comes default with
> WinME, Win2k and WinXP. Put the following code into a file called e.g.
> shutdwn.vbs. If you run it without any input arguments, it will reboot
> the local computer. If you add one or more remote computer names/ip
> addresses on the command line, the script will do a reboot of the
> remote computer(s).
>
>
> If you want a forced shutdown, change
> ShutDown oArgs(i), "Shutdown"
> to
> ShutDown oArgs(i), "Shutdown_Force"
>
>
> ' script start
> Set oArgs = WScript.Arguments
>
> If oArgs.Count = 0 Then
> ' local computer
> ShutDown ".", "Shutdown"
> Else
> For i = 0 to oArgs.Count - 1
> ShutDown oArgs(i), "Shutdown"
> Next
> End If
>
>
>
> Sub ShutDown(sNode, sAction)
>
> ' First parameter:
> ' use "." for local computer
>
> ' Second parameter:
> ' 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
>
> 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 an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/community/scriptcenter/default.mspx



Relevant Pages

  • Re: remote Shutdown Command
    ... The flavour you use is different again from the three flavours I previously ... Where does the command reside? ... Instead of just running shutdown, ... \\Computer Specifies a remote computer to shutdown. ...
    (microsoft.public.win2000.general)
  • Re: remote restart of Windows 2003
    ... running windows 2003 ... So I fire up a command window on the XP box and type...? ... Tried the Remote Shut Down freeware but getting the error "maybe you ... Instead of using some questionable freeware shutdown program, ...
    (microsoft.public.windows.server.general)
  • Re: remote Shutdown Command
    ... have a native shutdown command. ... \\Computer Specifies a remote computer to shutdown. ... unless you're calling a batch file called "shutdown.bat" (which I hope ...
    (microsoft.public.win2000.general)
  • Re: Help with a script.
    ... > command on the command line e.g. c:\runthis.bat ... to the remote computer before it starts it. ... Another freeware program with similar merits to PsExec is Beyondexec. ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.scripting)
  • Re: Control Dual Boot Remotely
    ... I normally use Remote Desktop to operate this computer and I shut it down ... or reboot it using "shutdown" from the command line. ... My question - is there a way to remotely reboot this computer into the ...
    (microsoft.public.windowsxp.work_remotely)