How do you query for WMI namespaces?
So I know about WMI namespaces because I read that they exits and I know I can connect to say:
root\cimv2
My question is what if I didn't know what namespaces were there, how would I go about querying for the available namespaces?
I just sort of want to go exploring the WMI and not have to look up each namespace.
I'm using WBEMtest, but I'll take anything, .NET, winapi.h, what have you.
WMI uses the namespace System access control lists (SACL) to audit namespace activity. To enable auditing of WMI namespaces, use the Security tab on the WMI Control to change the auditing settings for the namespace.
The default WMI namespace is Root/CIMV2 (since Microsoft Windows 2000). To use Windows PowerShell to get WMI namespaces in the current session, use a command with the following format.
I understand that you got your answer but wanted to show how easy it is in PowerShell to get a list of namespaces:
Get-WMIObject -namespace "root" -class "__Namespace" | Select Name
To enumerate all the namespaces, you must first connect to the root
namespace, query for all the __NAMESPACE
instances, and for each instance recursively repeat this process.
check these samples
Delphi
procedure GetListWMINameSpaces(const RootNameSpace:String;const List :TStrings;ReportException:Boolean=True);//recursive function
var
objSWbemLocator : OleVariant;
objWMIService : OleVariant;
colItems : OLEVariant;
colItem : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
sValue : string;
begin
try
objSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
objWMIService := objSWbemLocator.ConnectServer(wbemLocalhost, RootNameSpace, '', '');
colItems := objWMIService.InstancesOf('__NAMESPACE');
oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
while oEnum.Next(1, colItem, iValue) = 0 do
begin
sValue:=VarStrNull(colItem.Name);
colItem:=Unassigned;
List.Add(RootNameSpace+'\'+sValue);
GetListWMINameSpaces(RootNameSpace+'\'+sValue,List);//recursive
end;
except
if ReportException then
raise;
end;
end;
VbScript
strComputer = "."
Call EnumNameSpaces("root")
Sub EnumNameSpaces(strNameSpace)
WScript.Echo strNameSpace
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
"\" & strNameSpace)
Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")
For Each objNameSpace In colNameSpaces
Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
Next
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With