Downloads
19829.zip

Do you have a scripting-related question or problem? You can send your question or problem to bobwells@win2000mag.com.

I've written scripts that automate tasks when a Windows NT server starts up. Now I want to automate tasks when an NT server shuts down. Where can I find information about how to automate tasks during server shutdown?

NT doesn't support shutdown scripts, but Windows 2000 does. As a result, your options are to seek a third-party solution or upgrade to Win2K.

The only third-party solution I'm familiar with is an unsupported, old (posted in 1997), open-source utility called NEWGINA (http://wwwthep.physik.uni-mainz.de/~frink/nt.html). This utility replaces NT's Graphical Identification and Authentication (GINA). Because NEWGINA replaces GINA with an unsupported component, I strongly suggest that you upgrade to Win2K instead.

Upgrading to Win2K is the safest option. Win2K's Group Policy technology provides script policies, which you can use to create shutdown scripts. To learn more about how to create shutdown scripts, see my Windows 2000 Magazine Scripting Solutions article "Windows 2000 Script Policies" (October 1999—http://www.win2000mag.com, InstantDoc ID 7223).

My company has about 300 Win2K and NT servers. I'd like to measure the availability of each server based on certain events (i.e., events 6005, 6006, and 6009) in the event log and generate a report that shows its uptime, downtime, and availability (uptime - downtime)/uptime). How can I use CScript to automate this process so that the reports are generated daily without any operator involvement?

You can use Windows Management Instrumentation (WMI) to automate this task. You can choose from three different approaches: permanent WMI event subscriptions, temporary WMI event subscriptions, or a WMI script that periodically queries the appropriate event log for the target events.

Permanent WMI event subscriptions notify you in realtime of events you specify at an interval you specify. Permanent event subscriptions persist across reboots. Using these subscriptions involves creating a Managed Object Format (MOF) file and registering the permanent event subscriptions in the Common Information Model (CIM) schema.

Like permanent WMI event subscriptions, temporary WMI event subscriptions notify you in realtime of events you specify at an interval you specify. However, temporary WMI event subscriptions don't persist across reboots. Using these subscriptions involves writing a script that calls the SWbemServices::ExecNotificationQuery method.

For an overview of both temporary and permanent event subscriptions, see Alexander Nosov, "Understanding WMI Eventing," September 2000. For examples of how to use event subscriptions in scripts, see Alexander Nosov, "Use WMI Eventing to Monitor Your System," October 2000. In addition, in the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com), you can find an example script, wmiEvents.vbs, that monitors and records temporary WMI event subscriptions. To run this script, follow these steps:

  1. Launch the script by typing
    C:\> cscript wmievents.vbs
    at the command line.

  2. Raise an event by performing an action that causes the system to write an event to the event log (e.g., starting the Telnet service). In response, WMI traps and returns the event to the script.

  3. Press Ctrl+C to stop the script's execution.

If you don't want to use permanent or temporary event subscriptions, you can write a WMI script that periodically queries the appropriate event log for the target events. In my Windows 2000 Magazine Scripting Solutions article "Windows Script Files in Action" (June 2000—http://www.win2000mag.com, InstantDoc ID 8631), I discuss how to create a console-oriented utility that uses such a script. The utility consists of the WMI script, EventLog.wsf, and a supporting file, Library.vbs. EventLog.wsf is a Windows Script Host (WSH) 2.0 script that leverages WMI's Scripting API to search event logs. You can use this utility to search for the 6005, 6006, and 6009 events in your event logs. You can find EventLog.wsf, Library.vbs, and a Help file (usage.txt) in the Code Library on the Windows Scripting Solutions Web site.

Of these three WMI solutions, using permanent event subscriptions is the best long-term solution. Although permanent event subscriptions are slightly more complicated to initially define and set up, they require the least amount of ongoing maintenance and management.

Where can I find information about how to use WMI to access the registry? I want to retrieve all the subkeys and values under certain registry keys. API information about this topic is scarce.

As you probably know, Windows Script's (WS's) registry-related methods don't support registry enumeration. However, you can use WMI's Registry Provider (StdRegProv) to access and enumerate registry keys and values. To learn how to use StdRegProv's EnumKey and EnumValues methods, go to the Microsoft Developer Network (MSDN) Online Library at http://msdn.microsoft.com/library/psdk/wmisdk/regprovref_6yie.htm. Click EnumKey or EnumValues to obtain detailed information (including sample code) about that particular method.