Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show all services

Status
Not open for further replies.
Mar 29, 2004
120
US
This script is right out of the book, and is supposed to show all services running on local machine.



strComputer = "."
set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colItem = objWMIService.ExecQuery ("Select * from Win32_Service")
for each colItem in colItems
Wscript.Echo objItem.Name
Next



I get an error:

Line:8

Char: 1

Object not a collection



Basically telling me that objItem is not a collection, but how can I fix it?



Thanks

 
Replace this:
Set colItem = objWMIService.ExecQuery ("Select * from Win32_Service")
With this:
Set colItem[!]s[/!] = objWMIService.ExecQuery ("Select * from Win32_Service")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
this works:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Service")
For Each colItem In colItems
WScript.Echo objItem.Name
Next
 
I guess you'd replace this:
Wscript.Echo objItem.Name
with this:
Wscript.Echo colItem.Name

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top