Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Disable Services in a VB Script?

Posted on 2003-11-19
Medium Priority
Last Modified: 2010-04-13
Is it possible to disable system services in a visual basic script?  If so can anyone provide the source code?!?  It is to run as a logon script on a lab of WindowsXP machines connected to a Windows 2000 Domain.
Question by:CliftonAdmin
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
  • 2
  • 2

Accepted Solution

Rindbaek earned 750 total points
ID: 9786033
Below is a script that stops all dependent services for the apache2 service, then it stops the service and finally disables it replace the service name withe one(s) you need to stop

Its basically a modified version of :

You can find the description of win_32classes here:


' **********************CUT Script below***********************

strComputer = "."

'First we stops all dependent services (may not be needed and can then be deleted)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='Apache2'} Where " & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For each objService in colServiceList

'now wait 20 seconds for the dependent services to stop (could be more, could be less)
Wscript.Sleep 20000

'Stops the actual service
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='Apache2'")
For each objService in colServiceList
errReturn = objService.StopService()

'Disables the actual service
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Baseservice where Name='Apache2'")
For each objService in colServiceList
errReturn = objService.ChangeStartMode("Disabled")

' remove the  '  from the next line while testing.
' Wscript.Echo "Done"


Author Comment

ID: 9791097
Thanks very much your script didn't work, I didn't try to debug though because the script from Microsoft worked great!  Cheers.


Expert Comment

ID: 9795947
I think the problems is that some of the lines has been wrap'ed

in my browser its this line:
Set colServiceList = objWMIService.ExecQuery("Associators of " & "{Win32........

so all this should be on a single line or have an _ attched at the end of the line to show that the line continues below.

Set colServiceList = objWMIService.ExecQuery("Associators of " & "{Win32_Service.Name='Apache2'} Where "  & "AssocClass=Win32_DependentService " & "Role=Antecedent" )

 could be rewritten like this:

Set colServiceList = objWMIService.ExecQuery("Associators of " & _
 "{Win32_Service.Name='Apache2'} Where "  & _
 "AssocClass=Win32_DependentService " & "Role=Antecedent" )

Sorry that I didn't think about that.


Author Comment

ID: 9807184
Yep that did fix it... thanks for following through when I already accepted the answer.

You have been a great help.


Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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