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

Why isn't this "Check Service" script working?

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
US
I'm trying to get this srcipt to ask for the computer to be checked and then the service to check the status of and I've been unable to get it working so far. The following is just the latest non-working version of it.

Thanks in advance for the help!
Code:
On Error Resume Next 
Dim strComputer
Dim strService
strComputer = InputBox("Enter the name of the Computer:") 
strService = InputBox("Enter the name of the Service:")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = strService")
For Each objItem in colItems 
    Wscript.Echo "Service Name: " & objItem.Name & VBNewLine & "State: " & objItem.State
Next

[!]The AutoSavers![/!] [2thumbsup]
 
Change this line to what I have shown below.

Code:
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = '" & strService & "'")

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top