Sign in to follow this  
Followers 0
tinkythomas

Disable service in xp

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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:


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you so much! I can never get literal strings right. I can never work out where to put a single or double quote :mellow:

All is now working perfectly!

Share this post


Link to post
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
Sign in to follow this  
Followers 0