How to restart a service from the CMD

7,755

Setting the value in the Registry will not update the Service Control Manager's in-memory information. The supported method is to use the SCM's API, or a command-line program that does so for you:

sc config bthserv start= demand

Note the service name, bthserv, is the service's ID as opposed to its display name. You can see the ID of a given service in its properties window in the Services MMC snap-in (services.msc).

You will then be able to start the service as normal.

Bizarrely, though manually whacking the Registry does make Services show the new altered state, the service is still effectively disabled. I tested this and found that it will only become truly enabled by using the supported method or possibly after a reboot. Since your script is already using a Windows utility (net), also using sc won't reduce its portability at all.

Share:
7,755

Related videos on Youtube

13aal
Author by

13aal

Updated on September 18, 2022

Comments

  • 13aal
    13aal over 1 year

    I have a python script that will start a bluetooth service via the registry by replacing the Start value with manual what I need to do is restart the service from the CMD. Now I know I can do this by typing: net start "Bluetooth Support Service" however when I do this after running my script it does not find the service and outputs this:

    C:\Users\z-perkins-thomas\Documents\bin\python\fix-dap>net start "Bluetooth Support Service"
    
    System error 1058 has occurred.
    
    The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
    

    What is the correct way to restart a service after it has been re-enabled?

  • 13aal
    13aal about 7 years
    Changing the registry key value from 4 to 3, changes the value in services.msc to manual as it should.
  • Ben N
    Ben N about 7 years
    @13aal This is pretty strange - though Services shows the whacked state, the SCM doesn't seem to fully know about the change. It will only become truly enabled if you use a supported method. In general, it's preferable to use the dedicated API instead of fiddling with the Registry. Fortunately, also using sc to reconfigure the service (instead of the Registry-altering script) won't make your solution any less portable, since you already depend on net.
  • 13aal
    13aal about 7 years
    why is that though? Do you have any idea, you'd think that a direct registry edit would propagate immediately
  • Ben N
    Ben N about 7 years
    @13aal My guess is that the SCM loads the information from the Registry on startup and only updates its in-memory knowledge when a reconfiguration is done through its API. (Kind of like how Registry changes to display settings need a logon/logoff cycle unless you use the API that notifies the appropriate applications of the change.) I'm not sure why the Services snap-in sees the non-effective changes, but I do have empirical evidence that Services can be wrong if direct Registry manipulation is in play.