Jump to content
Sign in to follow this  
Sunsawe

How to explore wmi objects?

Recommended Posts

Hi,

A lot of people is using the wmi service. Usually it looks like that:

Func _ServGetDetails($iName, $Computer = ".")
    Local $Rtn = ''
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objService in $sItems
        If $objService.Name == $iName Then
        $Rtn &= $objService.SystemName & '|' & $objService.Name & '|' & $objService.ServiceType & '|' & $objService.State & '|'
        $Rtn &= $objService.ExitCode & '|' & $objService.ProcessID & '|' & $objService.AcceptPause & '|' & $objService.AcceptStop & '|'
        $Rtn &= $objService.Caption & '|' & $objService.Description & '|' & $objService.DesktopInteract & '|' & $objService.DisplayName & '|'
        $Rtn &= $objService.ErrorControl & '|' & $objService.PathName & '|' &$objService.Started & '|' & $objService.StartMode & '|'
        $Rtn &= $objService.StartName
        Return StringSplit($Rtn, '|')
        EndIf
    Next
    Return SetError(-1)
EndFunc

I would like to know if there is a way to "explore" the $objService without knowing its attributs. Something like:

foreach $attribut in $objService
  $attribut.getName()
  $attribut.getValue()

Thanks

Share this post


Link to post
Share on other sites

If I understood your question correctly, this should do the trick...

Func _EnumWMIclassInstances($classname, $servername = ".")
    Local $service = ObjGet("winmgmts:\\" & $servername & "\root\cimv2")
    Local $security = $service.Security_
    $security.ImpersonationLevel = 3
    Local $collection = $service.InstancesOf($classname)
    For $object In $collection
        For $property in $object.Properties_
            ConsoleWrite($property.Name & ": " & $property.Value & @CR)
        Next
    Next
EndFunc

_EnumWMIclassInstances("Win32_Service")
Edited by ArthurB

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...