Using a Group Policy WMI filter to test for a registry value

by Jeremy Saunders on May 10, 2009

I wanted a clean and simple way to prevent group policies applying during an automated build process. This is because it can potentially cause some of the components of the build process to fail. One of the last tasks to run on all servers built using my unattended build method will stamp the registry with the build version and date, so I was pretty eager to implement a WMI filter that would read the build version to determine whether or not the policy should apply. Easier said than done! I found a great article on WMI Filters that went into the requirements and gave an example, but I found that I still needed to do a considerable amount of research in order for everything to start making sense.

Copy the below MOF file to…

%SystemRoot%\System32\wbem

Compile it by typing…

Mofcomp -class:forceupdate BuildInfo.mof

Test it by typing…

Wmic path BuildInfo WHERE (BuildVersion Like “2.%”) get BuildVersion

This will return the build number from the registry for all 2.x builds

WMI Filter will be…

select * from BuildInfo where (BuildVersion Like “2.%”)

This will return True for all version 2.x builds

Please review the MOF file below. It is fully documented, and will help anyone who wants to implement the same process.

Enjoy!


///////////////////////////////////////////////////////////////////////////
// BuildInfo MOF File
// This MOF File makes it possible to query for the server build version
// and date with a Group Policy WMI filter. It’s specifically handy for
// Citrix XenApp builds, as it prevents the GPO from applying during a
// server build that potentially cause some of the components of the build
// process to fail.
//
// Release 1.0
// Written by Jeremy@jhouseconsulting.com.au on 6th May 2009.
//
// Copy it to…
// %SystemRoot%\System32\wbem
//
// Compile it by typing…
// mofcomp.exe -class:forceupdate %SystemRoot%\System32\wbem\BuildInfo.mof
//
// Test it by typing…
// Wmic path BuildInfo WHERE (BuildVersion Like “2.%”) get BuildVersion
// This will return the build number from the registry for all 2.x builds
//
// WMI Filter will be…
// select * from BuildInfo where (BuildVersion Like “2.%”)
// This will return True for all version 2.x builds
//
// Reference: http://grouppolicy.editme.com/WMIFilters
///////////////////////////////////////////////////////////////////////////

// First we must register the System Registry Provider by declaring and
// creating the Property Provider used to enumerate registry data and
// values from specific registry locations.
// It is important to understand that if the data that you want to report
// is contained within several subkeys in a registry location, you must
// use an Instance Provider instead.

#pragma namespace (“\\\\.\\root\\cimv2″)

instance of __Win32Provider as $PropProv
{
Name=”RegPropProv”;
Clsid=”{72967901-68EC-11d0-B729-00AA0062CBB7}”;
};

instance of __PropertyProviderRegistration
{
Provider=$PropProv;
SupportsPut = TRUE;
SupportsGet = TRUE;
};

// Now we define the registry Class With Qualifiers
#pragma namespace (“\\\\.\\root\\cimv2″)

[DYNPROPS]
class BuildInfo
{
[key]string Keyname=””;
string BuildVersion;
string BuildDate;
};
[DYNPROPS]
instance of BuildInfo
{
KeyName=”BuildInfo”;
[PropertyContext(“Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Datacom\\Build|Version”), Dynamic, Provider(“RegPropProv”)] BuildVersion;
[PropertyContext(“Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Datacom\\Build|Build Date”), Dynamic, Provider(“RegPropProv”)] BuildDate;
};
///////////////////////////////////////////////////////////////////////////

Jeremy Saunders

Jeremy Saunders

Technical Architect | DevOps Evangelist | Software Developer | Microsoft, NVIDIA, Citrix and Desktop Virtualisation (VDI) Specialist/Expert | Rapper | Improvisor | Comedian | Property Investor | Kayaking enthusiast at J House Consulting
Jeremy Saunders is the Problem Terminator. He is a highly respected IT Professional with over 35 years’ experience in the industry. Using his exceptional design and problem solving skills with precise methodologies applied at both technical and business levels he is always focused on achieving the best business outcomes. He worked as an independent consultant until September 2017, when he took up a full time role at BHP, one of the largest and most innovative global mining companies. With a diverse skill set, high ethical standards, and attention to detail, coupled with a friendly nature and great sense of humour, Jeremy aligns to industry and vendor best practices, which puts him amongst the leaders of his field. He is intensely passionate about solving technology problems for his organisation, their customers and the tech community, to improve the user experience, reliability and operational support. Views and IP shared on this site belong to Jeremy.
Jeremy Saunders
Jeremy Saunders

Previous post:

Next post: