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

How do I use a variable in place of a service name during a WMI Query

Status
Not open for further replies.

tfujitani

Programmer
Nov 5, 2002
6
US
I got the following script from Microsoft Technet. I want to modify it so that instead of having to enter the service name into the script, the user can specify the service. In other words, how do I replace 'DbService' with a variable?

I've tried ...Where Name = '" & Variable & "'" & chr(34))

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'DbService'")
For Each objService in colListOfServices
objService.StopService()
objService.Delete()
Next



 
strService = InputBox("Enter service name")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & strService & "')
For Each objService in colListOfServices
objService.StopService()
objService.Delete()
Next
 
Oops. missing quote at the end

strService = InputBox("Enter service name")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & strService & "'")
For Each objService in colListOfServices
objService.StopService()
objService.Delete()
Next



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top