Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you query for WMI namespaces?

Tags:

wmi

wmi-query

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.

like image 555
Matt Avatar asked Mar 16 '11 22:03

Matt


People also ask

How do I find my WMI namespace?

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.

What is the default WMI 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.


2 Answers

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
like image 172
ravikanth Avatar answered Sep 23 '22 12:09

ravikanth


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
like image 33
RRUZ Avatar answered Sep 20 '22 12:09

RRUZ