Restarting a Computer

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The ability to programmatically restart a computer allows administrators to perform many computer management tasks remotely. For example, if you create a script to install software or make a configuration change that requires restarting a computer, you can include the restart command in the script and perform the entire operation remotely.

The Win32_OperatingSystem class includes a Reboot method that can be used to restart a computer. Like the Win32Shutdown method, the Reboot method requires the user whose security credentials are being used by the script to possess the Shutdown privilege. In addition, the Shutdown privilege must be explicitly included in the script moniker.

Scripting Steps

Listing 8.25 contains a script that restarts a computer. To carry out this task, the script must perform the following steps:

  1. Use a GetObject call to connect to the Win32_OperatingSystem class. This call returns a collection consisting of the operating system currently in use on the computer.

    Because restarting a computer requires the Shutdown privilege, this privilege must be included as part of the moniker.

  2. For each operating system in the collection, use the Reboot method to restart the computer.

Listing 8.25   Restarting a Computer

1 2 3 4 5 6 7 8 9 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _         strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _     ("SELECT * FROM Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems     objOperatingSystem.Reboot() Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net