Jump to content

how to count services number ?


datas2k
 Share

Recommended Posts

Hi!

My quaestion is how im count the number of existing services ?

$objWMIService      = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$Services           = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", BitOR(0x10,0x20))

ConsoleWrite ("----------------------" & @LF & UBound($Services) & @LF & "----------------------" & @LF)
Im ask that cus after getting the services list, counting with UBound not work, always get a zero value.

For example with that loop im can count:

For $objItem In $Services
    $i = $i+1
Next

.... but im think it is an ugly method.

Link to comment
Share on other sites

Hi!

My quaestion is how im count the number of existing services ?

$objWMIService      = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$Services           = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", BitOR(0x10,0x20))

ConsoleWrite ("----------------------" & @LF & UBound($Services) & @LF & "----------------------" & @LF)
Im ask that cus after getting the services list, counting with UBound not work, always get a zero value.

For example with that loop im can count:

For $objItem In $Services
    $i = $i+1
Next

.... but im think it is an ugly method.

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colProcessList = $objWMIService.ExecQuery("Select * from Win32_Service")

ConsoleWrite($colProcessList.Count & " services found.")
For $objProcess In $colProcessList
    ConsoleWrite($objProcess.Name)
Next
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...