Previous Page
Next Page

Retrieving Hotfix Information Step-by-Step Exercise

In this section, you use the Win32_QuickFixEngineering provider to retrieve information about hotfixes installed on your server. This lab incorporates techniques learned in earlier chapters into the information about WMI discussed in this chapter.

1.
Open \My Documents\Microsoft Press\VBScriptSBS\Templates\BlankTemplate.vbs in Notepad or your favorite script editor.

2.
Turn on Option Explicit by typing Option Explicit on the first line of the script.

3.
Declare variables to be used in the script. There are six variables to be used: strComputer, objWmiService, wmiNS, wmiQuery, objItem, and colItems.

4.
Assign the value of "." to the variable strComputer. The code will look like the following:

strComputer = "."

5.
Assign the value of "\root\cimv2" to the variable wmiNS. The code will look like the following:

wmiNS = "\root\cimv2"

6.
Assign the query "Select * from Win32_QuickFixEngineering" to the variable wmiQuery. The code will look like the following:

wmiQuery = "Select * from Win32_QuickFixEngineering"

7.
Use the winmgmts moniker and the variable objWMIService as well as the GetObject method to make a connection to WMI. Use the strComputer and the wmiNS variables to specify the computer and the namespace to use. The code will look like the following:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)

8.
Set the variable colItems to be equal to the connection that comes back from WMI when it executes the query defined by wmiQuery. Your code should look like the following:

Set colItems = objWMIService.ExecQuery(wmiQuery)

9.
Use a For Each...Next construction to iterate through the collection called colItems. Assign the variable called objItem to each of the items returned from colItems. Your code should look like this:

For Each objItem In colItems

10.
Use WScript.Echo to echo out items such as the caption, CSName, and description. You can copy the following items, or use the WMI SDK to look up Win32_QuickFixEngineering and choose items of interest to you.

WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "CSName: " & objItem.CSName
WScript.Echo "Description: " & objItem.Description
WScript.Echo "FixComments: " & objItem.FixComments
WScript.Echo "HotFixID: " & objItem.HotFixID
WScript.Echo "InstallDate: " & objItem.InstallDate
WScript.Echo "InstalledBy: " & objItem.InstalledBy
WScript.Echo "InstalledOn: " & objItem.InstalledOn
WScript.Echo "Name: " & objItem.Name
WScript.Echo "ServicePackInEffect: " & objItem.ServicePackInEffect
WScript.Echo "Status: " & objItem.Status

11.
Close out your For Each...Next loop with the Next command.

12.
Save your file as YourNameSBSQueryHotFix.vbs and run it in CScript.exe. If you do not get the expected results, compare your script with \My Documents\Microsoft Press\VBScriptSBS\ch08\StepByStep\SBSQueryHotFix.vbs.


Previous Page
Next Page