Jump to content
Sign in to follow this  

how to enable and start a disabled service

Recommended Posts


hello the world.

just this silly question asked in the title.

i'm checking the status of a service with wmi and need to start it if disabled.

if change it's state in the registry from 4 to 2 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv

and need to manualy start it. i receive an error message when i try to do a "net start" command.

if i do it via the managemnt console all is fine.

is there another key to change to be able to do a "net start" or another prg to run to change the status of the service from "disable" to "auto" or "manual".

thx for your answers

Share this post

Link to post
Share on other sites

ok, i've just looked at your code (very impressive), i think i'll lose a lot of time to understand the function.

so if someone have something already done and small.

i'll be pleased.

Share this post

Link to post
Share on other sites

_SetServiceState(@ComputerName, "Norton AntiVirus Auto Protect Service", "Start")

Func _SetServiceState($s_pcname, $s_servicename, $State)
    Local $colItems = "", $even = 1, $objItem, $ret_status = -1, $s_pc
    Local $a_status[25] = ["Success", "Not supported", "Access denied", "Dependent services running", _
            "Invalid service control", "Service cannot accept control", "Service not active", "Service request timeout", _
            "Unknown failure", "Path not found", "Service already stopped", "Service database locked", "Service dependency deleted", _
            "Service dependency failure", "Service disabled", "Service logon failed", "Service marked for deletion", "Service no thread", _
            "Status circular dependency", "Status duplicate name", "Status - invalid name", "Status - invalid parameter", _
            "Status - invalid service account", "Status - service exists", "Service already paused"]
    If ($s_pcname <> $LV_ERR) Then
        If Ping($s_pcname) Then
            Local $objWMIService = ObjGet("winmgmts:\\" & $s_pcname & "\root\CIMV2")
            If @error Then
                MsgBox(16, "_SetServiceState", "ObjGet Error: winmgmts")
            $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _
                $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
            If @error Then
                MsgBox(16, "_SetServiceState", "ExecQuery Error: SELECT * FROM Win32_Service")
            If IsObj($colItems) Then
                For $objItem In $colItems
                    If $objItem.Name = $service Then
                            Case $State = "Boot" Or $State = "System" Or $State = "Automatic" Or $State = "Manual" Or $State = "Disabled"
                                $ret_status = $objItem.ChangeStartMode ($State)
                            Case $State = "Stop"
                                $ret_status = $objItem.StopService ()
                            Case $State = "Start"
                                $ret_status = $objItem.StartService ()
                            Case $State = "Pause"
                                $ret_status = $objItem.PauseService ()
                            Case $State = "Resume"
                                $ret_status = $objItem.ResumeService ()
                            Case $State = "Delete"
                                $ret_status = $objItem.Delete ()
EndFunc  ;==>_SetServiceState

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.