Jump to content

Disable service in xp


Recommended Posts

Hi,

I am trying to modify a vbscript for use in autoit. The code I have is as follows:

_DisableService("Alerter", "Disabled")

Func _DisableService($service, $State)
    
    Dim $objWMIService, $colServiceList, $objService, $errReturnCode
    Dim $strComputer
    
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    
    ;ConsoleWrite($objWMIService)

    $colServiceList = $objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name = " & "'" & $service & "'" & '"')
    
    ;ConsoleWrite($colServiceList)

    For $objService In $colServiceList
        If $objService.State = "Running" Then
            $objService.StopService()
            Sleep(5000)
        EndIf
        $objService.ChangeStartMode($State)
    Next

EndFunc   ;==>_DisableService

But this doesn't work and I can't figure it out. Can anyone help me?

Thanks

Link to comment
Share on other sites

  • Developers

Try:

_DisableService("Alerter", "Disabled")
Func _DisableService($service, $State)
    Dim $objWMIService, $colServiceList, $objService, $errReturnCode
    Dim $strComputer
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
;ConsoleWrite($objWMIService)
    $colServiceList = $objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name = '" & $service & "'")
;ConsoleWrite($colServiceList)
    For $objService In $colServiceList
        If $objService.State = "Running" Then
            $objService.StopService()
            Sleep(5000)
        EndIf
        $objService.ChangeStartMode($State)
    Next
EndFunc  ;==>_DisableService

Jos :mellow:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...