Simon336697
asked on
Querying multiple services
Hi guys.
I have a number of services on a remote machine that I would like to query and return the status of eg.whether they are running or not.
I have a tool called psservice
Standalone, it does the following...
psservice \\computer query browser
and displays...
C:\>FOR /F i > c:\cunt.txt"
C:\>psservice query browser
PsService v2.21 - Service information and configuration utility
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com
SERVICE_NAME: Browser
DISPLAY_NAME: Computer Browser
Maintains an updated list of computers on the network and supplies this list to computers designated as browsers. If this ser
vice is stopped, this list will not be updated or maintained. If this service is disabled, any services that explicitly depen
d on it will fail to start.
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,IG NORES_SHUT DOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
What I have done is create 2 files.
------------ services.txt (a list of services i want to query)
xmlprov
aspnet_state
wzcsvc
wmi
wscsvc
-------------qs.cmd (the command to run)
FOR /F %i in (services.txt) do "psservice query %i"
The above doesnt seem to work.
Any help greatly appreciated.
I have a number of services on a remote machine that I would like to query and return the status of eg.whether they are running or not.
I have a tool called psservice
Standalone, it does the following...
psservice \\computer query browser
and displays...
C:\>FOR /F i > c:\cunt.txt"
C:\>psservice query browser
PsService v2.21 - Service information and configuration utility
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com
SERVICE_NAME: Browser
DISPLAY_NAME: Computer Browser
Maintains an updated list of computers on the network and supplies this list to computers designated as browsers. If this ser
vice is stopped, this list will not be updated or maintained. If this service is disabled, any services that explicitly depen
d on it will fail to start.
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,IG
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
What I have done is create 2 files.
------------ services.txt (a list of services i want to query)
xmlprov
aspnet_state
wzcsvc
wmi
wscsvc
-------------qs.cmd (the command to run)
FOR /F %i in (services.txt) do "psservice query %i"
The above doesnt seem to work.
Any help greatly appreciated.
ASKER
Thanks merowinger.
Could i just ask tho...
how in your example, would you be able to query multiple services?
Thank you for your help :.)
Could i just ask tho...
how in your example, would you be able to query multiple services?
Thank you for your help :.)
as u can see here, u can make the service variable...so u can create an array or read the servicenames from a textfile or something else!!!
strComputer = Inputbox("Type in the pc name")
strService1 = "Messenger"
strService2 = "Alerter"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("S ELECT * FROM Win32_Service Where Name ='" &strService1 &"'")
For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "Started: " & objItem.Started
WScript.Echo "StartMode: " & objItem.StartMode
WScript.Echo "State: " & objItem.State
Next
Set colItems = objWMIService.ExecQuery("S ELECT * FROM Win32_Service Where Name ='" &strService2 &"'")
For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "Started: " & objItem.Started
WScript.Echo "StartMode: " & objItem.StartMode
WScript.Echo "State: " & objItem.State
Next
strComputer = Inputbox("Type in the pc name")
strService1 = "Messenger"
strService2 = "Alerter"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("S
For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "Started: " & objItem.Started
WScript.Echo "StartMode: " & objItem.StartMode
WScript.Echo "State: " & objItem.State
Next
Set colItems = objWMIService.ExecQuery("S
For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "Started: " & objItem.Started
WScript.Echo "StartMode: " & objItem.StartMode
WScript.Echo "State: " & objItem.State
Next
ASKER
Champion thank you so much.
You have been a great help merowinger, thanks mate.
S
You have been a great help merowinger, thanks mate.
S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you guys and sorry about the delay :<(
strComputer = Inputbox("Type in the pc name")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("S
For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "Started: " & objItem.Started
WScript.Echo "StartMode: " & objItem.StartMode
WScript.Echo "State: " & objItem.State
Next