Jump to content

Recommended Posts

Posted

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)
Posted (edited)

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
Posted (edited)

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
  • Solution
Posted

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

Posted

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?

Posted (edited)

I don't have any "%(COM%)" qualifying entries...

 

Ah I see, that's all I want. Also the .count() failed. Am I missing something on using this method?

Edited by JonBMN
Posted (edited)

It's not "count()", it's "count"

edit: I guess you programmer types would say it's not a method it's a property

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

Posted

It's not "count()", it's "count"

edit: I guess you programmer types would say it's not a method it's a property

 

Tried that first off and it didn't work and that's why I tried to put the '()'. My bad on the method - property mistake.

Posted

The code that I posted runs on my machine (Vista).  Make sure you remove the last parm ("48") from the query.

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

Posted (edited)

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

Posted (edited)

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

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
×
×
  • Create New...