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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript

Status
Not open for further replies.

Sat87

Technical User
Aug 25, 2011
2
US
I am having some problems in writing a vbscript for finding the status of a service in a list of machines provided in a txt file. The service name is "SMS Agent Host Service". I tried to import the machine names from the txt file and export the result in a spreadsheet, in 2 columns - Machine Name and Service Status.

Can anyone please help me out here with a vbscript to do the above ?
 
what code do you have so far?

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I have this code which helps find a service is running or not... but i am nor able to export it to an excel sheet.

Code:
---------
OPTION EXPLICIT

DIM strComputer,strServiceName
strComputer = "." ' Local Computer
strServiceName = "ccmexec" ' Windows Update Service

IF isServiceRunning(strComputer,strServiceName) THEN
wscript.echo "The '" & strServiceName & "' service is running on '" & strcomputer & "'"
ELSE
wscript.echo "The '" & strServiceName & "' service is NOT running on '" & strcomputer & "'"
END IF

' Function to check if a service is running on a given computer
FUNCTION isServiceRunning(strComputer,strServiceName)
DIM objWMIService, strWMIQuery

strWMIQuery = "Select * from Win32_Service Where Name = '" & strServiceName & "' and state='Running'"

SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isServiceRunning = TRUE
ELSE
isServiceRunning = FALSE
END IF

END FUNCTION
 
What about the code used to export to a csv? Are you using an Excel object or text stream?

-Geates



"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top