WMI SQL Queries with Joins

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the samples I saw with WMI, we can use a SQL like query to get system information ( "Select * From SomeWMIClass" ).

Can I use joins to get WMI classes correlated data ??

For example: I want to join Win32_NetworkAdapter with Win32_NetworkAdapterConfiguration to get a result set with information from the two classes in a single resultset.

How to join multiple WMI classes ??

Something like this

Select Win32_NetworkAdapter.AdapterType, Win32_NetworkAdapter.Caption, Win32_NetworkAdapterConfiguration.IPAddress, Win32_NetworkAdapterConfiguration.MACAddress
From Win32_NetworkAdapter, Win32_NetworkAdapterConfiguration
Where Win32_NetworkAdapter.ID = Win32_NetworkAdapterConfiguration.ID ( ??

Thanks.
 
Hi,

Thanks for your post. I am checking this issue and will update you with my
findings.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hello,

Based on my research, you can do that by view provider by creating the
appropriate mof. Save following text between the lines in a mof file say
a.mof and then run
mofcomp a.mof

Then connect to root\sample_views namespace and get instances of class
Join_NetAdapterAndConfig.

//----------------------mof content-----------------
#pragma namespace("\\\\.\\root\\sample_views")

instance of __Win32Provider as $DataProv
{
Name = "MS_VIEW_INSTANCE_PROVIDER";
ClsId = "{AA70DDF4-E11C-11D1-ABB0-00C04FD9159E}";
ImpersonationLevel = 1;
PerUserInitialization = "True";
};

instance of __InstanceProviderRegistration
{
Provider = $DataProv;
SupportsPut = True;
SupportsGet = True;
SupportsDelete = True;
SupportsEnumeration = True;
QuerySupportLevels = {"WQL:UnarySelect"};
};


[JoinOn("Win32_NetworkAdapter.index =
Win32_NetworkAdapterConfiguration.Index"),
ViewSources
{
"Select * from Win32_NetworkAdapter",
"Select * from Win32_NetworkAdapterConfiguration"
},
ViewSpaces
{
"\\\\.\\root\\cimv2",
"\\\\.\\root\\cimv2"
},
dynamic, provider("MS_VIEW_INSTANCE_PROVIDER")]
class Join_NetAdapterAndConfig
{

[PropertySources{"AdapterType",""}]
string AdapterType;

[PropertySources{"Caption",""}]
string Caption;

[key,
PropertySources{"index","index"}]
uint32 ID;

[PropertySources{"","IPAddress"}]
string IPAddress[];

[PropertySources{"","MACAddress"}]
string MACAddress;

};
//----------------------end of-------------------------

Here's the link to learn more about view provider
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/view_provider.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top