Previous Page
Next Page

Invoking the WMI Moniker to Display the Machine Boot Configuration

In this section, you explore an alternate method of invoking the WMI moniker. In so doing, you write a WMI script that displays the boot configuration of a machine.

1.
Open Notepad or your favorite script editor.

2.
On the first line, type Option Explicit to ensure you declare all variables used in the script.

3.
Declare three variables. The variables are objWMIService, colItems, and objItem.

4.
Set objWMIService equal to what comes back from the GetObject method when used in conjunction with the WMI moniker. In addition, define an impersonation level of Anonymous. Your code will look like the following:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=anonymous}")

5.
Set colItems equal to what comes back from issuing the WQL statement "Select * from Win32_BootConfiguration" as you use the ExecQuery method. Your code will look like the following:

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BootConfiguration")

6.
Use a For Each...Next loop to iterate through colItems as you look for the following properties of the Win3_BootConfiguration object: BootDirectory, Caption, ConfigurationPath, Description, LastDrive, Name, ScratchDirectory, SettingID, and TempDirectory. Use the variable objItem to assist you in iterating through the collection. Make sure you close out the For Each...Next loop with the Next command. Your code will look like the following:

For Each objItem In colItems
  WScript.Echo "BootDirectory: " & objItem.BootDirectory
  WScript.Echo "Caption: " & objItem.Caption
  WScript.Echo "ConfigurationPath: " & objItem.ConfigurationPath
  WScript.Echo "Description: " & objItem.Description
  WScript.Echo "LastDrive: " & objItem.LastDrive
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "ScratchDirectory: " & objItem.ScratchDirectory
  WScript.Echo "SettingID: " & objItem.SettingID
  WScript.Echo "TempDirectory: " & objItem.TempDirectory
  WScript.Echo
Next

7.
Save your work as BootConfigA.vbs.

8.
Use CScript to run the script. It will fail! Why does the script fail? Hint: Check the impersonation level.

9.
Change the line containing the WMI moniker. Set the impersonation level to Identify.

10.
Save your work as BootConfigB.vbs.

11.
Use CScript to run the script. It will fail!

12.
Why does the script fail? Hint: Check the impersonation level.

13.
Change the line containing the WMI moniker. Set the impersonation level to Impersonate.

14.
Save your work as BootConfigC.vbs.

15.
Use CScript to run the script. It works just fine. Why does the script work?

16.
Change the line containing the WMI moniker. Set the impersonation level to Delegate.

17.
Save your work as BootConfigD.vbs.

18.
Use CScript to run the script. It works just fine. What does this tell you about using the different impersonation levels on Windows Server 2003?


Previous Page
Next Page