Jump to content

WMI Object Length


JonBMN
 Share

Go to solution Solved by kylomas,

Recommended Posts

I'm trying to get the length of the WMI object I have created. I've tried using .count() and .length() to no avail. Can anyone shed some light on maybe something I'm missing?

Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
If @error Then Return SetError(@error, 0, "")
Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)
MsgBox(0, "", "Number of Ports: " & $oItems)
Link to comment
Share on other sites

Hi,
 
Maybe like this :

Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
If @error Then Return SetError(@error, 0, "")
Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)
 
Local $iCount = 0
For $oItem In $oItems
    $iCount += 1
Next
 
MsgBox(0, "", "Number of Ports: " & $iCount)

_
Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi,

 

Maybe like this :

Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
If @error Then Return SetError(@error, 0, "")
Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)
 
Local $iCount = 0
For $oItem In $oItems
    $iCount += 1
Next
 
MsgBox(0, "", "Number of Ports: " & $iCount)

_

Br, FireFox.

 

Yes, that is a solution. Not the solution I was hoping for as I was hoping there would be a method for finding the length, but thank you all the same.

Edited by JonBMN
Link to comment
Share on other sites

  • Solution

JonBMN,

Try this (had to alter the script to make it run and altered the query to get results)...

Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
;If @error Then Return SetError(@error, 0, "")
;Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)
Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL") ; use default parms

ConsoleWrite($oItems.count & @LF)

See >this link for an explanation.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

JonBMN,

Try this (had to alter the script to make it run and altered the query to get results)...

Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
;If @error Then Return SetError(@error, 0, "")
;Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)
Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL") ; use default parms

ConsoleWrite($oItems.count & @LF)

See >this link for an explanation.

kylomas

 

Why did you need to change the ExecQuery?

Link to comment
Share on other sites

Try this...

Local $iCount = _GetComCount()
MsgBox(0, '', 'Number of Ports: ' & $iCount)


Func _GetComCount($sComputer = @ComputerName)
    Local $objWMI = ObjGet('winmgmts:\\' & $sComputer & '\root\CIMV2')
    If @error Or Not IsObj($objWMI) Then Return SetError(@error, 0, '')
    Local $objClass = $objWMI.InstancesOf('Win32_PnPEntity WHERE Name LIKE "%(COM%)"')
    Return $objClass.Count
EndFunc
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Read the link I pointed you to.  It explains the count parameter.

edit: The "48" you are using is probably several parms combined.  You can manipulate them any way you want or use ripdad's example.  They pretty much do the same thing.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

×
×
  • Create New...