Using MOF Files

Whenever you manage WMI, or systems that use WMI, you might use or see MOF files. WMI data (such as definitions of namespaces, classes, instances, or providers) are sometimes represented in MOF files. MOF files are a convenient way to change WMI settings and to transfer WMI objects between computers. The contents of MOF files only become effective when the files are compiled. For more information about compiling MOF files, see the "Using WMI Management Tools" section earlier in this appendix.

One of the most powerful uses of MOF files with SMS is to extend SMS inventory collection. This is typically done by editing the SMS_def.mof file. For more information, see Chapter 2, "Collecting Hardware and Software Inventory."

The WMI SDK provides complete details about the syntax of MOF files. The following MOF example illustrates a typical (though simple) MOF file. The highlights are:

  • Lines between braces ({ and }) are part of a single definition. Some WMI elements can be defined in a single line (properties, for example), but others that require multiple lines for a definition (classes, for example) are defined within braces. The name and type of the definition immediately precedes the first brace.

  • Lines between brackets ([ and ]) are qualifiers that apply to the definition that follows it. Qualifiers can apply to the entire class or instance, or they can apply to particular properties. The placement of the qualifier determines which level it affects.

  • The #pragma lines are instructions to the MOF Compiler. Usually, these lines specify which namespace should be used. That namespace will be used for all definitions until the next #pragma line.

  • If a provider is required by a class or instance definition, it must be defined in the MOF file prior to the definition of the class or instance. The details for defining the provider will be included with the documentation that is provided with the provider (or the product that the provider is part of).

#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\\Windows NT\\
 CurrentVersion\\Hotfix")
]
class HotFixes
{
  [key]
  string  QNumber;
  [PropertyContext("Installed")]
  uint32 Installed;
};
#pragma namespace("\\\\.\\root\\cimv2\\sms")
[SMS_Report(TRUE),
SMS_Group_Name("Hotfixes"),
SMS_Class_ID("MICROSOFT|HOTFIXES|1.0")]
class HotFixes : SMS_Class_Template
{
  [SMS_Report(TRUE),key]
  string  QNumber;
  [SMS_Report(TRUE)]
  uint32 Installed;
};
For More Information

Did you find this information useful? Please send your suggestions and comments about the documentation to smsdocs@microsoft.com.