Sign in to follow this  
Followers 0
Sunsawe

How to explore wmi objects?

7 posts in this topic

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



#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

why don't you all look at scriptomatic for AutoIt and see how it's done.....

Look in Downloads


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

i say scriptomatic is the tool you're probabbly looking for.

btw there are auotit tags that actually highlight you're script...

Edited by DBak

[center][/center]

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  
Followers 0