Permanent Configuration Settings

[Previous] [Next]

Many services require keeping permanent configuration settings. (We discussed how to use the registry for this purpose in Chapter 5.) As an alternative, you can create properties in a Win32_Service-derived class. A third option is to use a standard provider that ships with WMI. To use this provider, you just have to write a suitable MOF file.

WMI keeps all of its configuration information, such as the directory location of auto-recover MOF files and start-up heap allocation size, under the following registry key:

 HKEY_LOCAL_MACHINE\Software\Microsoft\WBEM 

The following MOF file defines a class derived from the CIM_Setting class. The derived class allows you to use WMI to see these WBEM registry settings.

 #pragma namespace("\\\\.\\root\\cimv2") // Instance provider instance of __Win32Provider as $InstProv {     Name    = "RegProv" ;     ClsId   = "{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}" ; }; instance of __InstanceProviderRegistration {     Provider = $InstProv;     SupportsPut = TRUE;     SupportsGet = TRUE;     SupportsDelete = FALSE;     SupportsEnumeration = TRUE; }; [dynamic, provider("RegProv"),  ClassContext("local|hkey_local_Machine\\software\\microsoft\\wbem")] class Richter_MySettings : CIM_Setting {   [key,PropertyContext("CIMOM")] string  SettingId;   [PropertyContext("Autorecover MOFs")] string AutoRecoverMOFs[];   [PropertyContext("Startup Heap Preallocation Size")]      uint32 HeapPreAllocationSize; }; 

NOTE
These values are already exposed via the Win32_WMISetting class. This MOF file is for demonstration purposes only.

Note two important features of this MOF file. First, the standard registry provider is declared and registered using the "instance of Win32Provider" and "instance of InstanceProviderRegistration" syntax. This declaration and registration might already have been done if a developer used the registry provider in the CIMV2 namespace. Doing it a second time has no ill effect.

Second, the declaration of the settings subclass is handled using the "class Richter_MySettings" statement. Critical to note here is the association of the class with the registry provider by using the provider qualifier, and the association of the property with the registry fields using the PropertyContext qualifiers. The PropertyContext qualifiers indicate which registry values the property values are to be mapped to.



Programming Server-Side Applications for Microsoft Windows 2000
Programming Server-Side Applications for Microsoft Windows 2000 (Microsoft Programming)
ISBN: 0735607532
EAN: 2147483647
Year: 2000
Pages: 126

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