Windows – How to restart a service from the CMD

bluetoothcommand linewindowswindows 7windows-services

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?

Best Answer

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.

Related Question