Enumerating Objects

   

It's easy to enumerate all the objects, such as Win32_LogicalDisk , that are available to you. The third page in my WMI demo program does just this, and can be seen running in Figure 19.4. The reported list of objects is very long, and they won't all fit in a single browser screen ”that's why you can't see all the objects in the figure.

Figure 19.4. All the WMI objects have been enumerated.

graphics/19fig04.gif

The code for the page in Figure 19.4 can be seen in Listing 19.4. The code starts off by creating a new ManagementClass object. It then creates an EnumerationOptions class, and the EnumerateDeep property is set to false. Then, walking through the collection in a for each construct allows you to examine all the objects.

Listing 19.4 Enumerating Through the WMI Objects
 ManagementClass newClass = new ManagementClass();  EnumerationOptions options = new EnumerationOptions();  options.EnumerateDeep = false;  foreach( ManagementObject o in newClass.GetSubclasses( options ) )  {      Response.Write( o["__Class"] + "<br>\r\n" );  } 
   


Special Edition Using ASP. NET
Special Edition Using ASP.Net
ISBN: 0789725606
EAN: 2147483647
Year: 2002
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net