Previous Page
Next Page

Choosing Specific Instances

In many situations, you will want to limit the data you return to a specific instance of that class in the data set. If you go back to your query and add a Where clause to the Select statement, you'll be able to greatly reduce the amount of information returned by the query. Notice that in the value associated with the WMI query, you added a dependency that indicated you wanted only information with share name C$. This value is not case-sensitive, but it must be surrounded with single quotation marks, as you can see in the wmiQuery string in the following script. These single quotation marks are important because they tell WMI that the value is a string value and not some other programmatic item. Because the addition of the Where statement was the only thing you really added to the ListShares.vbs script, we're not going to go into a long discussion of the ListSpecificShares.vbs script.

ListSpecificShares.vbs

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem

strComputer = "."
wmiNS = "\root\cimv2"
wmiQuery = "Select path, allowMaximum from win32_Share" &_
   " where name = 'C$'"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)

For Each objItem in colItems
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "Path: " & objItem.path
  WScript.Echo "AllowMaximum: " & objItem.AllowMaximum
Next

Just the Steps

To limit specific data

1.
Make a connection to WMI.

2.
Use the Select statement to choose the specific property you are interested in (for example, Select name).

3.
Use the From statement to indicate the class from which you want to retrieve data (for example, From Win32_Share).

4.
Add a Where clause to further limit the data set that is returned. Make sure the properties specified in the Where clause are first mentioned in the Select statement (for example, where name).

5.
Add an evaluation operator. You can use the equal sign, or the less than or greater than symbols (for example, where name = 'C$').



Previous Page
Next Page