Announcement

Collapse
No announcement yet.

Script for disabling services

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script for disabling services

    I have a script for disabling services already that I modified from one I found online. (A batch file really)

    Does anyone have a script that they would share for turning off services? This script works ok, but If a service doesn't stop quickly enough, it messes up the batch and starts showning dos command format help.
    I already know I'm not that bright. Please be constructive. Only give your 2cents if it helps. Don't be condesending or demeaning. It doesn't make you look smart. You just look like an arse.
    Chris Robertson
    The Computer Doctor

  • #2
    Re: Script for disabling services

    I use this to check if it is disabled. If it is not i call the stop service and disable it.

    Thre is probably a more elegant way of doing it but this works for me.

    Code:
    		'Disable the Windows Firewall on users machines
    		If Checkstate = "" Then
    			Call UpdateComponentsDiv("<b>Firewall not installed on this machine. Please update to at least Windows XP Service Pack 2.</b>")
    			ElseIf	Checkstate = "true" Then
    				StopService				
    				Call UpdateComponentsDiv("<b>The Windows firewall is now disabled</b>")
    				ElseIf Checkstate = "false" Then
    					Call UpdateComponentsDiv("<b>The Windows firewall Service is already disabled</b>")
    		End If
    Code:
    	Function Checkstate 
    
    		strComputer = "."
    		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    		Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
    		For Each objItem in colItems
    			If  objitem.displayname = "Windows Firewall/Internet Connection Sharing (ICS)" Then
    				If objitem.started = "False" Then
    					Checkstate = "false"
    				Else 
    					Checkstate = "true"
    				end If	
    				Exit For 
    			End If
    		Next
    	End Function
    Code:
    	Function StopService				
    
    		StrComputer = "."
    		Set objWMIservice = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
    		Set Colitems = ObjWMIservice.execquery ("Select * from win32_service",,48)
    		For Each objitem In colItems
    				If  objitem.displayname = "Windows Firewall/Internet Connection Sharing (ICS)" Then
    					If objitem.started = "True" Then
    						objitem.StopService ("Windows Firewall/Internet Connection Sharing (ICS)")
    						objitem.ChangeStartMode ("Disabled")
    					End If
    				Exit for
    				End If
    		Next
    	End Function

    Comment


    • #3
      Just following up here is the basic script that can be tailored to your need. This batch checks if the service is even available then if it is running, echos the service name, stops the service if running and disables the service.

      =====code start
      echo.&echo.&echo =====Disable services=====
      echo.
      for %%x in (
      "Mcx2Svc"
      "NetTcpPortSharing"
      "RemoteRegistry"
      "SharedAccess"
      "fax"
      "TabletInputService"
      "RemoteAccess"
      "UxSms"
      "Bdesvc"
      "EFS"
      "wuauserv"
      "wsearch"
      ) do (sc query %%x| find "STATE" >nul 2>&1 && sc query %%x| find "RUNNING" >nul 2>&1 && echo Stop and Disable service: %%x && net stop %%x && sc config %%x start= disabled)
      ======end code
      I already know I'm not that bright. Please be constructive. Only give your 2cents if it helps. Don't be condesending or demeaning. It doesn't make you look smart. You just look like an arse.
      Chris Robertson
      The Computer Doctor

      Comment

      Working...
      X