Now let's look on this computer for an object to manage: the C drive. I don't know the exact name of this element in CIM or WMI, so rather than browse the hundreds of classes that CIM Studio lists, I click the Find button (the binoculars at the top of the lefthand pane). In the resulting Search for Class dialog box, which Figure 2 shows, I type the name of a keyword that I think will likely be in the C-drive class name and click Go! Because I'm looking for a named partition and I know that Windows OSs call such partitions logical disks or logical drives, I search for the keyword logical. You could also search for disk, but you'd have to scroll through a lot more results.
Figure 2 shows the available classes. I select Win32_LogicalDisk and click OK, and the window in Figure 3 appears. (Why not CIM_LogicalDisk? As I mentioned previously, Win32 is the prefix for any object WMI manages. If you select CIM_LogicalDisk and try to display instances, you won't see any specific information about the available logical disks—you'll just see a Win32_LogicalDisk entry for each available logical drive.) The righthand pane now shows the available properties for the Win32_LogicalDisk class. Note that the property values are empty because we're looking at the class, not at a particular instance of the class. To display the instances of the Win32_LogicalDisk class, I click the Instances button at the top of the righthand pane (fourth button from the right).
The resulting window lists all the instances of logical disks on this particular machine, including network-accessible logical drives, in the righthand pane. I click the instance with device ID "C:". The resulting window, which Figure 4 shows, displays the properties and methods of the selected instance on tabs in the righthand pane. The name of the logical disk you selected appears at the top of the righthand pane.
You can use a script to change the properties or to apply the methods. If you have questions about the properties, select the Win32_LogicalDisk class or Win32_LogicalDisk.DeviceID="C:" instance and click the Help button. You'll see documentation for most of the object's available properties and methods.
Starting to Script
Now that you've had a look at the Win32_LogicalDisk class and its properties, I want to give you a feel for working with this information in a script. If the Microsoft Windows 2000 Resource Kit is installed on your computer, listfreespace.vbs is located by default in the \program files\resource kit folder. This script queries each object in the Win32_LogicalDisk class for the values of a couple of its properties: DeviceID (its drive letter) and FreeSpace (the number of bytes of free space it has). On a computer where A is the floppy disk drive and D is the CD-ROM drive, listfreespace.vbs's output might look something like this:
A: not available
C: 8,243,381,248 bytes
D: not available
G: 4,776,943,616 bytes
You can use getfree.vbs, which Listing 1 shows, to obtain similar information with less code. I've heavily commented the script so that you can tell exactly how it works. You supply a drive letter when you invoke the script, and getfree.vbs tells you the free space and file system for the drive. For example, if I type
getfree.vbs c:
on my laptop, I see the window that Figure 5 shows.
Now you know what WMI is and how to find managed objects on your computer. You might not yet be an expert WMI "scripter," but you'll know what pieces to manipulate and where they are when you write scripts.
|
Related Articles in Previous Issues |
You can obtain the following articles from Windows 2000 Magazine's Web site at http://www.win2000mag.com.
DARREN MAR-ELIA
"Leveraging Windows Management Instrumentation in Win2K Pro," Summer 2000, InstantDoc ID 8819
MARK RUSSINOVICH
Internals, "Inside Windows Management Interface," February 2000, InstantDoc ID 7937
BOB WELLS
Scripting Solutions, "WMI Monikers," May 2001, InstantDoc ID 20401
Scripting Solutions, "Windows Management Instrumentation: The Systems Administrator's Apprentice," August 2000, InstantDoc ID 9033
Scripting Solutions, "Windows Management Instrumentation: The Journey Begins," July 2000, InstantDoc ID 8959
|
i badly need of a script
I will just input the from&to ip address and an exe name
The script should report me the ip address of the machines which contains that exe
can any one pls help me reg this.
sathish June 10, 2002