RegKeyToMof - A Bit on How it Works

Profile picture for user PaulW

I'd been using RegKeyToMof for the first time in a while in the last few months and thought some of us may want a deeper dive into how it works.  I'm not going to cover directly on how to use it as Garth has covered that quite well over here: https://www.enhansoft.com/how-to-use-regkeytomof-2/

This post will be more on what it is doing.  Hope you find it useful or interesting.

First, let's quickly review what RegKeyToMof does or rather the problem it solves.  The tool is designed to let us easily add registry keys to hardware inventory in CM.  Remember, CM hardware inventory is basically reading selected WMI classes from a computer and sending them back to the CM database.  So, knowing this information, you can conclude that RegKeyToMof is moving the registry key information into WMI somehow.  So, how is this done?

When you create a custom inventory with the tool, you start by appending to the CM configuration.mof file (located in <CM install directory>\inboxes\clifiles.src\hinv). Configuration.mof is used by CM to extend hardware inventory (See https://docs.microsoft.com/en-us/sccm/core/clients/manage/inventory/extend-hardware-inventory).  Take a few minutes and look through the configuration.mof file once.  If you look, you'll see a few familiar items, Add/Remove Programs, and Office 365 (anything that starts with // is a comment).  Let's sidetrack and take a look at the Office 365 inventory section.

//----------------------
// Office365ProPlusConfigurations
//----------------------

#pragma namespace ("\\\\.\\root\\cimv2")
#pragma deleteclass("Office365ProPlusConfigurations", NOFAIL)

[DYNPROPS]
Class Office365ProPlusConfigurations
{
	[key] string KeyName;
	String InstallationPath;
	String ClientFolder;
	String VersionToReport;
	String ClientCulture;
	String CDNBaseUrl;
	String UpdatesEnabled;
  String AutoUpgrade;
	String UpdateChannel;
  String cfgUpdateChannel;
	String Platform;
	String UpdateUrl;
	String SharedComputerLicensing;
	String GPOChannel;
  String UpdatePath;
	String LastScenario;
	String LastScenarioResult;
	String OfficeMgmtCOM;
  String CCMManaged;
  String GPOOfficeMgmtCOM;
};

[DYNPROPS]
Instance of Office365ProPlusConfigurations
{
	KeyName="Office365ProPlusConfigurations";
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|InstallationPath"),Dynamic,Provider("RegPropProv")] InstallationPath;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|ClientFolder"),Dynamic,Provider("RegPropProv")] ClientFolder;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|VersionToReport"),Dynamic,Provider("RegPropProv")] VersionToReport;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|ClientCulture"),Dynamic,Provider("RegPropProv")] ClientCulture;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|CDNBaseUrl"),Dynamic,Provider("RegPropProv")] CDNBaseUrl;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|UpdatesEnabled"),Dynamic,Provider("RegPropProv")] UpdatesEnabled;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|AutoUpgrade"),Dynamic,Provider("RegPropProv")] AutoUpgrade;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate|updatechannel"),Dynamic,Provider("RegPropProv")] UpdateChannel;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|updatechannel"),Dynamic,Provider("RegPropProv")] cfgUpdateChannel;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|Platform"),Dynamic,Provider("RegPropProv")] Platform;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|UpdateUrl"),Dynamic,Provider("RegPropProv")] UpdateUrl;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|SharedComputerLicensing"),Dynamic,Provider("RegPropProv")] SharedComputerLicensing;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate|updatebranch"),Dynamic,Provider("RegPropProv")] GPOChannel;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate|updatepath"),Dynamic,Provider("RegPropProv")] UpdatePath;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun|LastScenario"),Dynamic,Provider("RegPropProv")] LastScenario;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun|LastScenarioResult"),Dynamic,Provider("RegPropProv")] LastScenarioResult;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration|OfficeMgmtCOM"),Dynamic,Provider("RegPropProv")] OfficeMgmtCOM;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID\\{B7F1785F-D69B-46F1-92FC-D2DE9C994F13}|(Default)"),Dynamic,Provider("RegPropProv")] CCMManaged;
	[PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\office\\16.0\\common\\officeupdate|officemgmtcom"),Dynamic,Provider("RegPropProv")] GPOOfficeMgmtCOM;
};

In a nutshell, this "custom inventory," as a built in part of CM, puts the registry values from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration into WMI to report back in your hardware inventory.  This is how CM gets all of its data for the Office 365 dashboard, through their own custom inventory of the Office 365 registry keys.  So, configuration.mof is having the CM client build new WMI classes and then populates that class with the requested data from the registry.  Part 1 of RegKeyToMof is building compatible MOF code to extend in the configuration.mof.

Side note/rant. When extending your inventory, be sure you add to the end of the configuration.mof file.  When you look at the file, at the end, there is a commented section for extensions.  Add it there.  If you don't the next upgrade of current branch will clear it out.Where to add your extensions to hardware inventory

The second part of RegKeyToMof creates a class to import into CM client settings to enable the inventory of the class that was just created in the configuration.mof modification above.  So, this is how you get data into CM from the registry.

  1. Modification of Configuration.mof tell CM client to create and populate a new WMI class with the registry data specified.
  2. Adding a custom class to client settings tells the CM client to collect the data from the new WMI class that was created above.

Again, these are the 2 steps that you complete with RegKeyToMof as was outlined in Garth's blog post.

Some of us are probably asking or saying, "So What".  Or "Big deal, why do I care? It just works".  Well, I think it is always better to understand how something works.  This helps you troubleshoot any potential issues as well as be smarter with how you use the tool.

This kind of leads me to a few items to be aware of:

  • RegKeyToMof creates the new classes in the root\cimv2 namespace, by default.
    • Use a tool like WMI Explorer to view these classes.
    • Some created by configuration.mof by default include: Win32Reg_AddRemovePrograms, Win32Reg_AddRemovePrograms64, and Office365ProPlusConfigurations
  • root\cimv2 requires admin access to modify.  So, don't expect any user level modifications.
  • If you delete the extension in the configuration.mof, any existing inventory data will remain in the WMI class.  The WMI classes are not cleaned up.
    • So, don't test in production.  You could start littering WMI on all of your computers with a number of custom classes if you keep changing and adding to the configuration.mof.  Think about adding it once and calling it MySweetClass1.  Then MySweetClass2, and so on.  Lots of garbage that will probably stay in WMI for a very very long time on your computers.  Be a good steward and keep your environment tidy!
    • I've seen this done in production.  I get an immediate frowny face. :-(
    • Configuration.mof goes to EVERY computer with a CM client.  It's not targeted like a client setting.
Related Technology

Comments

Hi Paul

You wrote: "So, configuration.mof is having the CM client build new WMI classes and then populates that class with the requested data from the registry."

Do you know if it is possible to collect data directly from WMI instead of the registry?

I have created a Class (Test_Class) in WMI with some data, but I do not know how to fill out this part in the Configuration.mof:

[DYNPROPS]

Instance of Test_Class

{

What goes here?

};

 

/Emil

If you have data in wmi already, then the real work is done already.  From the hardware inventory in the Default Client Settings, you can browse to a computer with the existing wmi class and add it from there.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.