VBScript template for stopping/disabling services

Posted on 2008-06-18
Medium Priority
Last Modified: 2008-07-28
I need to stop and disable several services in MS Windows XP Pro via a vbscript.  Can someone assist me with a script template for this?
Question by:fmcsa004
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Accepted Solution

sr75 earned 252 total points
ID: 21816276
Here you go!!!
On Error Resume Next
dim strComputer
'Stop  and Start a Service
strServiceName = "Alerter"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"  & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
	wscript.sleep 1500
	wscript.echo objService.name	

Open in new window

LVL 65

Assisted Solution

RobSampson earned 248 total points
ID: 21817429
Hi, here's another version, and this will help too:
Hey, Scripting Guy! How Can I Disable a Service?


' Note: Each Service is case sensitive.
arrServices = Array("Print Spooler","Windows Audio","VNC Server")
' Server to stop services on
strServer = "D09790RING"
If Ping(strServer) = True Then
	For Each strService In arrServices
		Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" _
			& strServer & "\root\cimv2")
		Set colListOfServices = objWMIService.ExecQuery _
			("Select * from Win32_Service Where DisplayName='"& strService & "'")
		On Error Resume Next
		For Each objService In colListOfServices
			If Err.Number = 0 Then
				On Error GoTo 0
				If objService.State = "Running" Then
					Wscript.Sleep 5000
				End If
				objService.ChangeStartMode "Disabled"
				On Error GoTo 0
				WScript.Echo strService & " service was not found on " & strServer
			End If
	WScript.Echo strServer & " could not be pinged."
End If
WScript.Echo "Script finished."
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
		Ping = False
	End If
End Function

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question