I'm trying to develop a vbscript that will allow me to shutdown a PC
(running Windows XP Pro) on a Windows 2003 network. I would like to
implement this a policy for my laptop computer users. This policy
will check to see if the computer's virus defintions are upto date.
If not the laptop will be shutdown before the user can logon to our
network.

The script needs to be run when the PC first starts up, BUT before the
user logs on. I know where to set up the script (as part Local
Computer Policy -> Computer Configuration ->Windows Settings ->
Scripts (Startup/Shutdown) -> Startup). I've tried everything from
executing the windows shutdown command from a vbscript (shutdown.exe
-s -t 00) to various vbscript code including:

Const SHUTDOWN = 1
strComputer = "."
Set objWMIService = GetObject("winmgmts: {(Shutdown)}" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(SHUTDOWN)
Next

The problem is that the PC will not shut down. After the startup code
is excuted, I see the logon prompt. Which means I'm past the startup
script and into the user logon part of the entire authentication
process.

I know the shutdown code works. I've tested it while I've been logged
on. It shuts down the machine every time. I know that the shutdown
code was executed. I saw a test message. that I put after the
shutdown code. Yet the PC will not shutdown!

I think the problem is that I have the wrong permissions, but I'm
unsure how to fix the problem.

Any thoughts and script samples would be greatly appreciated.
Thanks in advance. ...Gary White

Re: Way to force shutdown of a PC from a script that is run when Windows by Torgeir

Torgeir
Sat Feb 28 11:01:25 CST 2004

Gary White wrote:

> I'm trying to develop a vbscript that will allow me to shutdown a PC
> (running Windows XP Pro) on a Windows 2003 network. I would like to
> implement this a policy for my laptop computer users. This policy
> will check to see if the computer's virus defintions are upto date.
> If not the laptop will be shutdown before the user can logon to our
> network.
>
> The script needs to be run when the PC first starts up, BUT before the
> user logs on. I know where to set up the script (as part Local
> Computer Policy -> Computer Configuration ->Windows Settings ->
> Scripts (Startup/Shutdown) -> Startup). I've tried everything from
> executing the windows shutdown command from a vbscript (shutdown.exe
> -s -t 00) to various vbscript code including:
> (snip WMI shutdown code)

Hi

Try the sub ShutDown in this post using "PowerOff_Force" as input parameter:

http://groups.google.com/groups?selm=3EB9B305.7E99B60%40hydro.com


If that doesn't work either, try PsShutdown.exe (using the command line
switches -k -f) in the free PsTools suite:

http://www.sysinternals.com/ntw2k/freeware/pstools.shtml


Please report your findings, I am very interested in the result :-)

--
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



Re: Way to force shutdown of a PC from a script that is run when Windows first starts up? by Clay

Clay
Sat Feb 28 12:24:50 CST 2004

On Sat, 28 Feb 2004 11:08:08 -0500, Gary White <gbw48@comcast.net>
wrote:

>I know the shutdown code works. I've tested it while I've been logged
>on. It shuts down the machine every time. I know that the shutdown
>code was executed. I saw a test message. that I put after the
>shutdown code. Yet the PC will not shutdown!
>
>I think the problem is that I have the wrong permissions, but I'm
>unsure how to fix the problem.
>
>Any thoughts and script samples would be greatly appreciated.
>Thanks in advance. ...Gary White

Startup scripts run in the context of the System account. Does the
System account have rights to shutown the PC? I got bit by this last
week.

Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"

Re: Way to force shutdown of a PC from a script that is run when Windows first starts up? by Gary

Gary
Tue Mar 02 07:21:53 CST 2004

On Sat, 28 Feb 2004 18:01:25 +0100, "Torgeir Bakken (MVP)"
<Torgeir.Bakken-spam@hydro.com> wrote:

>Gary White wrote:
>
>> I'm trying to develop a vbscript that will allow me to shutdown a PC
>> (running Windows XP Pro) on a Windows 2003 network. I would like to
>> implement this a policy for my laptop computer users. This policy
>> will check to see if the computer's virus defintions are upto date.
>> If not the laptop will be shutdown before the user can logon to our
>> network.
>>
>> The script needs to be run when the PC first starts up, BUT before the
>> user logs on. I know where to set up the script (as part Local
>> Computer Policy -> Computer Configuration ->Windows Settings ->
>> Scripts (Startup/Shutdown) -> Startup). I've tried everything from
>> executing the windows shutdown command from a vbscript (shutdown.exe
>> -s -t 00) to various vbscript code including:
>> (snip WMI shutdown code)
>
>Hi
>
>Try the sub ShutDown in this post using "PowerOff_Force" as input parameter:
>
>http://groups.google.com/groups?selm=3EB9B305.7E99B60%40hydro.com
>
>
>If that doesn't work either, try PsShutdown.exe (using the command line
>switches -k -f) in the free PsTools suite:
>
>http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
>
>
>Please report your findings, I am very interested in the result :-)
Torgeir, Thanks for getting back to me.
The first code stub worked when I ran it as a normal user. When I
tried it in my production environment (running is a startup script as
part of a group policy) it did not work.

However, the PsShutdown worked! I was finally able to shutdown the PC
from within a startup script!

Regards, ...Gary White

Re: Way to force shutdown of a PC from a script that is run when by Torgeir

Torgeir
Tue Mar 02 18:55:20 CST 2004

Gary White wrote:

> On Sat, 28 Feb 2004 18:01:25 +0100, "Torgeir Bakken (MVP)"
> >
> >Try the sub ShutDown in this post using "PowerOff_Force" as input parameter:
> >
> >http://groups.google.com/groups?selm=3EB9B305.7E99B60%40hydro.com
> >
> >If that doesn't work either, try PsShutdown.exe (using the command line
> >switches -k -f) in the free PsTools suite:
> >
> >http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
> >
> >Please report your findings, I am very interested in the result :-)
>
> Torgeir, Thanks for getting back to me.
> The first code stub worked when I ran it as a normal user. When I
> tried it in my production environment (running is a startup script as
> part of a group policy) it did not work.
>
> However, the PsShutdown worked! I was finally able to shutdown the PC
> from within a startup script!

Hi

Thanks for the feedback :-)

I had a suspicion that PsShutdown would work fine, it is the most perfect
and flawless shutdown/poweroff/reboot/logoff/suspend/hibernate utility I
ever have come by.

--
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