2 Replies - 544 Views - Last Post: 03 February 2013 - 02:37 PM Rate Topic: -----

#1 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

VBScript concatenation issue.

Posted 01 February 2013 - 02:29 PM

Hi all,
I am working through a scripting situation inwhich I need to create an array which has values that match the Win32_Service names of various services I am trying to shut off.

My first big obsticle is the proper syntactical concatenation mess that I currently have for a query into WMI.

Can anyone offer any insight into what it is that im missing?

Thanks!
Steven

Option Explicit
'On Error Resume Next

Dim StrComputer, strService
Dim objWMIService, objService
Dim colServiceList
Dim errReturnCode
dim svcFW, svcVPN, svcWWifi, svcSUS, svcDWMRCS
Dim arrServicesTBTO(4)

svcFW = "Service0"
svcVPN = "service1"
svcWWifi = "Service2"
svcSUS = "Service3"
svcDWMRCS = "Service4"

arrServicesTBTO(0) = svcFW
arrServicesTBTO(1) = svcVPN
arrServicesTBTO(2) = svcWWIFI
arrServicesTBTO(3) = svcSUS
arrServicesTBTO(4) = svcDWMRCS

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	
for each strService in arrServicesTBTO 

	Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = "'strService' )
	for each objService in colServiceList
		objService.StopService
		wscript.echo objService.DisplayName & " has been stopped."
	Next

Next



Is This A Good Question/Topic? 0
  • +

Replies To: VBScript concatenation issue.

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,858
  • Joined: 12-December 12

Re: VBScript concatenation issue.

Posted 01 February 2013 - 03:05 PM

("SELECT * FROM Win32_Service WHERE Name = '" & strService & "'")

[I prefer CAPITALS for SQL-keywords :)]
Was This Post Helpful? 1
  • +
  • -

#3 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

Re: VBScript concatenation issue.

Posted 03 February 2013 - 02:37 PM

Thank you Andrew. i'll plug that in when i have my test environment at work and report back.

THanks again.
Steven
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1