Hi
Testing this my self, I also get "A required privilege is not held
by the client" error message when a Power User runs the command
shutdown.exe -r -f
But when I used a VBScript/WMI solution, I could do a (forced) reboot
without any problems.
After some further research, I found out that the user must have both
Local and Remote Shutdown privileges for shutdown.exe to work.
So you can either add this Remote Shutdown privilege to the Power
Users group (A), or use the VBScript below (B).
A)
To add the Remote Shutdown privilege:
Log in with an user with local admin rights.
Start/Run --> gpedit.msc
Go to
Computer Configuration\Windows Settings\Security Settings
\Local Policies\User Rights Assignment\
Double click on "Force shutdown from a remote system"
Add the "Power Users" group.
B)
Instead, you can use a VBScript/WMI solution.
Put the code below into a file called e.g. shutdwn.vbs, run it with
the following command line:
wscript.exe "<path-to-vbs-file>" PowerOff_Force
'--------------------8<----------------------
Set oArgs = WScript.Arguments
If oArgs.Count = 0 Then
' PowerOff as default value
ShutDown ".", "PowerOff"
Else
ShutDown ".", oArgs(i)
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
MsgBox "Error: invalid input parameter!", _
vbExclamation + vbSystemModal, "ShutDown"
End Select
oOS.Win32shutdown iCmd
End Sub
'--------------------8<----------------------
--
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/scriptcenter/default.mspx