Solved

Disable Services in a VB Script?

Posted on 2003-11-19
4
481 Views
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.
0
Comment
Question by:CliftonAdmin
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Rindbaek earned 250 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 :
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/services/ScrSvc22.asp

You can find the description of win_32classes here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp

Cheers
Henning



' **********************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
objService.StopService()
Next

'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()
Next

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

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







0
 

Author Comment

by:CliftonAdmin
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.

Clifton.
0
 
LVL 8

Expert Comment

by:Rindbaek
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.

Henning
0
 

Author Comment

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

You have been a great help.

Clifton.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Migrate DHCP from server 2000 to 2008 1 632
Remote Access to a Windows 2000 Computer 2 508
Windows 2000 Sever Lab Setup 1 685
Building AD from Scratch 5 136
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…
This article describes how to reset your Windows 10 password when you've forgotten it.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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