How to shut down a PC through Command Line

  • Thread starter Thread starter Khalid Munir
  • Start date Start date
K

Khalid Munir

Hi there,
Can any one help me in this regard. I am trying to
shutdown Windows2000 Server by using the following command

rundll32.exe user32.dll,ExitWindowsEx

but in vain. Can any one pointout the error in the above
statement. Thanks in advances
Rgds.
Khalid Munir
 
Khalid Munir said:
Hi there,
Can any one help me in this regard. I am trying to
shutdown Windows2000 Server by using the following command

rundll32.exe user32.dll,ExitWindowsEx

but in vain. Can any one pointout the error in the above
statement. Thanks in advances
Rgds.
Khalid Munir

Save the following vbscript:


'===== Script Start =============

' "." for local computer
ShutDown ".", "Shutdown"



' 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



Sub ShutDown(sNode, sAction)
' For sNode, use "." for local computer

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

'======= Script End ====


.... and execute with 'cscript <your filename>.

(From the MS script collection)
 
Hi there,
Can any one help me in this regard. I am trying to
shutdown Windows2000 Server by using the following command

rundll32.exe user32.dll,ExitWindowsEx

but in vain. Can any one pointout the error in the above
statement. Thanks in advances

I believe that won't work with Win2k or XP.

You can use the shutdown.exe utility in the resource kit. Or PsShutdown
from Sysinternals http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
The PsTools package has some other cool utilities also, and they are free.

Note: those tools are all green software (Bill Gates used to know what that
was...), so they don't install a bunch of garbage all over your system.
 
Back
Top