Last active
July 14, 2023 10:28
-
-
Save Ioan-Popovici/6ff80f2eca450cce867d to your computer and use it in GitHub Desktop.
HWI EXT SQL Classes for SQL Server Product Reporting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===================================================== | |
//---------------| SQL extension start |--------------- | |
//===================================================== | |
/* | |
.SYNOPSIS | |
Gathers SQL product info. | |
.DESCRIPTION | |
Gathers SQL product info, id and product key and adds them to custom WMI Classes. | |
.NOTES | |
Created by Ioan Popovici. | |
.LINK | |
https://MEM.Zone/SW-SQL-Server-Products | |
.LINK | |
https://MEM.Zone/SQL-SupportFunctions | |
.LINK | |
https://MEM.Zone/SW-SQL-Server-Products-CHANGELOG | |
.LINK | |
https://MEM.Zone/SW-SQL-Server-Products-GIT | |
.LINK | |
https://MEM.Zone/ISSUES | |
*/ | |
//-- Set default WMI namespace | |
#Pragma NameSpace("\\\\.\\ROOT\\cimv2") | |
//----------| Old SQL extension cleanup |--------- | |
//-- !! UNCOMMENT TO ACTIVATE !! (Remove '//' from '//#Pragma') | |
//#Pragma DeleteClass("SQL_2022", NOFAIL) | |
//#Pragma DeleteClass("SQL_2019", NOFAIL) | |
//#Pragma DeleteClass("SQL_2017", NOFAIL) | |
//#Pragma DeleteClass("SQL_2016", NOFAIL) | |
//#Pragma DeleteClass("SQL_2014", NOFAIL) | |
//#Pragma DeleteClass("SQL_2012", NOFAIL) | |
//#Pragma DeleteClass("SQL_2008", NOFAIL) | |
//#Pragma DeleteClass("SQL_2000_And_2005", NOFAIL) | |
//---------------| SQL 2022 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2019_Property class contains information about the SQL 2022 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement16" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2019_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2019 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2019_Property class contains information about the SQL 2019 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement15" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2019_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2017 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2017_Property class contains information about the SQL 2017 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement14" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2017_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2016 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2016_Property class contains information about the SQL 2016 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement13" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2016_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2014 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2014_Property class contains information about the SQL 2014 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement12" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2014_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2012 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2012_Property class contains information about the SQL 2012 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement11" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2012_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2008 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_2008_Property class contains information about the SQL 2008 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement10" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_2008_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL 2000/2005 class |--------------- | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_Legacy_Property class contains information about the SQL 2000 and 2005 service. You can use this information for SQL version reporting."): ToInstance, | |
UNION, | |
ViewSources { | |
"SELECT PropertyIndex, PropertyName, PropertyNumValue, PropertyStrValue, ServiceName, SqlServiceType FROM SqlServiceAdvancedProperty WHERE SQLServiceType=1" | |
}, | |
ViewSpaces { | |
"\\\\.\\ROOT\\Microsoft\\SqlServer\\ComputerManagement" | |
}, | |
Dynamic, | |
Provider("MS_VIEW_INSTANCE_PROVIDER") | |
] | |
//- Class properties | |
Class SQL_Legacy_Property | |
{ | |
[PropertySources{"PropertyIndex"}, key] uint32 PropertyIndex; | |
[PropertySources{"PropertyName"}, key] string PropertyName; | |
[PropertySources{"PropertyNumValue"} ] uint32 PropertyNumValue; | |
[PropertySources{"PropertyStrValue"} ] string PropertyStrValue; | |
[PropertySources{"ServiceName"}, key] string ServiceName; | |
[PropertySources{"SqlServiceType"}, key] uint32 SqlServiceType; | |
}; | |
//---------------| SQL ProductID class |--------------- | |
#Pragma DeleteClass("SQL_ProductID", NOFAIL) | |
//-- Create custom WMI class | |
//- Class qualifiers | |
[ | |
Description("The SQL_ProductID class contains the obfuscated SQL license key. You can use this information for SQL reporting."): ToInstance | |
] | |
//- Class properties | |
Class SQL_ProductID | |
{ | |
[key] | |
string Release; | |
string ProductID; | |
boolean DigitalProductID[]; | |
}; | |
//- SQL 2022 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2022"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\160\\Tools\\ClientSetup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\160\\Tools\\ClientSetup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2019 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2019"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\150\\Tools\\ClientSetup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\150\\Tools\\ClientSetup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2017 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2017"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\140\\Tools\\ClientSetup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\140\\Tools\\ClientSetup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2016 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2016"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\130\\Tools\\ClientSetup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\130\\Tools\\ClientSetup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2014 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2014"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\120\\Tools\\Setup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\120\\Tools\\Setup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2012 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2012"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\110\\Tools\\Setup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\110\\Tools\\Setup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL 2008 class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "2008"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL10\\Setup|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL10\\Setup|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//- SQL Legacy class instance | |
[DYNPROPS] | |
Instance of SQL_ProductID | |
{ | |
Release = "Legacy"; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\90\\ProductID|ProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
ProductID; | |
[ | |
PropertyContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\90\\ProductID|DigitalProductID"), | |
Dynamic, | |
Provider("RegPropProv") | |
] | |
DigitalProductID; | |
}; | |
//===================================================== | |
//----------------| SQL extension end |---------------- | |
//===================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment