Sugg on service status query & Some batch file help...
Posted on 2004-08-02
1. How to query particualr service status using WMI
here i have the Script for getting all service status ...But I am looking for specific service status...Not all
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
For Each objItem in colItems
Wscript.Echo "DisplayName: " & objItem.DisplayName
Wscript.Echo "StartMode: " & objItem.StartMode
Wscript.Echo "State: " & objItem.State
otherwise I got a output like this....
DisplayName: Enterprise Security Agent
DisplayName: Event Log
DisplayName: COM+ Event System
DisplayName: Fax Service
DisplayName: HP ITO Agent
DisplayName: IIS Admin Service
Here i can get the service name using Findstr "DisplayName: IIS Admin Service". but how i can i get the next two line.
If i search for "StartMode: Auto" or "State: Running" it is goign to list all keys.
what i want is like this search for "DisplayName: Enterprise Security Agent" which is line 1 and print
the print line2 & line3 which is for Enterprise Security Agent.
then search for "DisplayName: Fax Service" which is "line 10" which is and print
the print line10 & line11 which is for Fax Service
how to do this in batch file.....