Jump to content

How to explore wmi objects?


Sunsawe
 Share

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

Link to comment
Share on other sites

  • 1 month later...

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

---------Arthur B

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...