Using WMI Classes in Visual Studio .NET

Encode USS Code 39 in Visual Studio .NET Using WMI Classes
Using WMI Classes
Creating Code 39 Extended In .NET Framework
Using Barcode generator for .NET Control to generate, create Code 3 of 9 image in .NET framework applications.
Using COM Objects
USS Code 39 Reader In .NET Framework
Using Barcode reader for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
After instantiation, accessing COM objects is the same as accessing NET objects, with two exceptions:
Paint Bar Code In Visual Studio .NET
Using Barcode generation for VS .NET Control to generate, create barcode image in .NET applications.
COM objects do not have constructors with parameters COM objects do not have static members
Bar Code Reader In Visual Studio .NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
Using WMI Classes
Generate Code 3 Of 9 In Visual C#.NET
Using Barcode maker for .NET Control to generate, create Code-39 image in .NET applications.
The commandlet Get-WmiObject and the integrated WPS types [WMI], [WMICLASS], and [WMISEARCHER] open the world of mighty Windows Management Instrumentation (WMI), which offers almost all modules of modern Windows operating systems in an object-oriented manner
Generating Code 39 Full ASCII In VS .NET
Using Barcode creator for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
NOTE This chapter assumes that you have a basic knowledge of WMI
Printing ANSI/AIM Code 39 In Visual Basic .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create Code 39 Full ASCII image in VS .NET applications.
8 USING CLASS LIBRARIES
ECC200 Generator In VS .NET
Using Barcode generator for VS .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications.
SystemManagement
Generating European Article Number 13 In Visual Studio .NET
Using Barcode encoder for VS .NET Control to generate, create EAN13 image in .NET framework applications.
Windows WPS uses the NET assembly SystemManagementdll with the namespace SystemManagement to access WMI Therein, a meta object model for access to WMI objects is realized However, access to WMI using COM classes is also possible; it is just more cumbersome and is not covered in this book Central classes of the object model (see Figure 83) of System Management are as follows:
Draw EAN / UCC - 14 In VS .NET
Using Barcode generation for .NET framework Control to generate, create EAN / UCC - 13 image in Visual Studio .NET applications.
ManagementObject
Encode UPC-A Supplement 2 In .NET
Using Barcode generator for .NET Control to generate, create UCC - 12 image in Visual Studio .NET applications.
This class represents a WMI object
Encode Code 2/5 In .NET
Using Barcode drawer for .NET Control to generate, create 2 of 5 Standard image in .NET framework applications.
ManagementClass
Encode Code-39 In C#
Using Barcode encoder for VS .NET Control to generate, create Code 3 of 9 image in Visual Studio .NET applications.
This class represents a WMI class ManagementClass is derived from ManagementObject
Generate GS1 128 In Java
Using Barcode drawer for Java Control to generate, create EAN128 image in Java applications.
ManagementBaseObject
GTIN - 13 Drawer In Java
Using Barcode maker for Java Control to generate, create EAN-13 Supplement 5 image in Java applications.
Both classes are derived from ManagementBaseObject This class is not abstract, but is also used at different places within the object model
Reading European Article Number 13 In .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
8
Code 128 Code Set A Generator In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create Code-128 image in ASP.NET applications.
Using Class Libraries
Barcode Generator In Visual C#.NET
Using Barcode generation for .NET Control to generate, create barcode image in Visual Studio .NET applications.
Subclass Of Management Class Subclass Of Methods Management ObjectCollection
Draw Barcode In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
Item
Bar Code Creator In .NET
Using Barcode creator for ASP.NET Control to generate, create bar code image in ASP.NET applications.
MethodData Collection Item MethodData
GetInstances() GetSubClasses () GetRelatedClasses() InParameters OutParameters
Management BaseObject PropertyData Collection Item PropertyData
Management Object
CreateInstance () GetRelationships
Properties SystemProperties
Properties SystemProperties
Path ClassPath
ManagementPath
ObjectGetOptions Options
ManagementScope Scope
Figure 83 Object model of SystemManagement In SystemManagementdll, the class ManagementObject serves as the meta class for all WMI classes (that is, an instance of ManagementObject is mapped to a WMI object during its creation via a WMI path and consequently displays this) Unfortunately, this mapping is not as easy to handle as one would want, because all properties have to be called via PropertyDataCollection (refer to Figure 83) and method calls must be made cumbersomely via InvokeMethod()
NOTE In the following sections, you will see that WPS extremely simpli es the access to COM by providing a WPS object adapter
WMI Support in WPS
WPS offers the option to access the local WMI repository, and WMI repositories on remote systems, too For this purpose, WPS offers the following constructs:
The commandlet Get-WmiObject (alias gwmi) The integrated WPS type indicators [WMI], [WMICLASS], and
[WMISEARCHER]
The WPS WMI object adaptor, which simpli es the access to WMI objects
Using WMI Classes
Accessing WMI Objects
To access a WMI object, you have three options:
Use of the commandlet Get-WmiObject with a lter and optionally with the indication of a computer name Use of the integrated WPS types [WMI] and [WMIClass] with WMI paths Direct instantiation of the classes SystemManagement ManagementObject (that is, SystemManagement ManagementClass with respective indication of a WMI path in the constructor)
TIP Classes, which can have only one instance anyway, can be called without any lter (see Figure 84):
Get-WmiObject Win32_ComputerSystem Get-WmiObject Win32_OperatingSystem 8 USING CLASS LIBRARIES
Figure 84 Win32_Computersystem and Win32_OperatingSystem exist only once in the WMI repository
8
Table 81 Accessing Single WMI Objects
Get-WmiObject
with Filter Integrated WPS Types [WMI] "\\\root\cimv2: Win32_LogicalDisk DeviceID='C:'" [WMI] "\\\root\cimv2: Win32_UserAccount Domain='ITV', Name='hs'" [WMI] "\\E02\root\cimv2: Win32_UserAccount Domain='ITV', Name='hs'" Direct Instantiating New-Object SystemManagement ManagementObject("\\ \root\cimv2:Win32_ LogicalDiskDeviceID='C:'") New-Object SystemManagement ManagementObject("\\\root\ cimv2:Win32_UserAccount Domain='ITV',Name='hs'") New-Object SystemManagement ManagementObject("\\E02\ root\cimv2: Win32_UserAccount Domain='ITV',Name='hs'") New-Object SystemManagement ManagementClass("\\E01\ root\cimv2:Win32_ UserAccount")
WMI Object of a WMI Class with One Key Property
Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'"
Using Class Libraries
WMI Object of a WMI Class with Two Key Properties WMI Object on a Remote System
Get-WmiObject Win32_Account - lter "name='hs' and domain='itv'" Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" -computer "E02"
WMI Class
Not possible
[WMICLASS] "\\\root\
cimv2:Win32_ UserAccount"
Using WMI Classes
NOTE A fundamental difference between Get-WmiObject and New-Object is that Get-WmiObject displays all existing instances of a WMI class (for example, all processes), whereas New-Object creates a new instance The semantics of Get-WmiObject do not apply to COM and NET objects because a central directory for instances does not exist Instead, WMI has the WMI repository How to display a list of all instances in COM and NET classes depends on the structure of the respective classes and cannot be expressed generally in WPS
Type Indicators
When using the type indicators [WMI] and [WMIClass], users often forget to set the path name in parentheses when it is a composite name The type indicators have a stronger binding than the plus operator (+) Wrong:
8 USING CLASS LIBRARIES $Computer = "E01" [WMI] "Win32_PingStatusAddress='"+ $Computer + " "
Right:
$Computer = "E01" [WMI] ("Win32_PingStatusAddress='"+ $Computer + " ")
The WMI Object Adapter
The normal access to WMI objects via NET is not really smooth because you always have to cumbersomely call PropertyDataCollection Here, WPS offers a simpli cation based on Extended Type System (ETS); WPS dynamically creates objects via the integrated WMI object adapter that comply with the WMI classes Figure 85 shows this complex relationship