Re: Remote OS Shutdown with WMI problems
- From: ng@xxxxxxxxxxxxxxxxx
- Date: Tue, 07 Nov 2006 21:37:36 +0100
Hi Josh,
Maybe this helps:
ObjOperatingSystem.Win32Shutdown(pFlag + pForceFlag)
pFlag
0 Logs off the current user
1 Shuts down the machine
2 Reboots the machine
8 Powers down the machine
pForceFlag
4 Forces a logoff, shutdown or reboot even if the user has unsafed work
10 Forces a logoff, shutdown or reboot even if software currently running has hung and does not respond to an End Task request.
Regards,
Richard
jtlovseth@xxxxxxxxx wrote:
I am trying to setup a script that will remotely shutdown a Windows.
2003 server. Using microsoft provided code I have simply added my
server name and the RemoteShutdown privilege to the to template and
have attempted to test it while logged in as domain administrator. The
code is below.
'---code start----
strComputer = "myremoteservername"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Shutdown, RemoteShutdown)}!\\"
& _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select Name from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(1)
Next
'---code end----
The problem is that it doesn't work in all cases:
1. This script will work if someone is logged into the server that is
being shutdown.
2. It will also sort-of work when no one is logged into the server and
the screen saver has kicked in. I say "sort-of work" because it
definitely receives and interprets the shutdown message however doesn't
actually shutdown the computer until someone goes to the console and
moves the mouse to cancel the screensaver. After the screensaver has
gone off it commences shutting down.
3. It doesn't work at all when the screensaver is not on and no one is
logged into the server.
Initially I thought, this is weird. Why would the same script work or
not work depending on whether a user is logged in or the screensaver is
on? At all times when I am testing this script I am domain
administrator so permissions shouldn't be a problem. I do see that when
I run the script the login attempt in the security log is successful
for my domain administrator account.
So I wanted to try another WMI script to see if had problems running
that in any of these cases. The other script I tried simply asked the
computer for what processes it was running. It is below:
'---code start----
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "myremoteservername"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcess
strList = strList & vbCr & _
objProcess.Name
Next
wSCript.Echo strList
wScript.Quit
'---code end----
This WMI script worked fine in all of the cases, whether no one was
logged in, the screen saver was on, or when someone was logged in.
In my wmiprov.log I do see some boot up errors but no errors in direct
relation to what I am trying to do.
So my question is why won't the shutdown script work when nobody is
logged into the machine but the other one works fine? Shouldn't my
domain administrator priviledges be enough? Why should it matter
whether someone is logged into the machine or whether the screen saver
is on?
Thanks for any insight you might have on this.
Josh
- References:
- Remote OS Shutdown with WMI problems
- From: jtlovseth
- Remote OS Shutdown with WMI problems
- Prev by Date: Re: Determing file version through WMI
- Next by Date: Re: Determing file version through WMI
- Previous by thread: Re: Remote OS Shutdown with WMI problems
- Next by thread: SNMP trap
- Index(es):
Relevant Pages
|