VBScript template for stopping/disabling services

Posted on 2008-06-18
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 63 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

Open in new window

LVL 65

Assisted Solution

RobSampson earned 62 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

627 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