How do I enable services on a Windows computer via a command line?
I believe the command you are looking for is:
sc config servicenamehere start= auto
You'll need to know the name of the service though - to view this from the command line, try this command - this will show all services:
sc query type= service state= all
If you want to see only stopped services, run this command:
sc query type= service state= inactive
The list of services output by the query can be quite long. You may filter it by using findstr
(see post here) . For example
sc query type= service state= all | findstr "ssh"
Will select the output lines of the services list that contain the string "ssh"
Note: For some services you may need also administrator privileges, you will notice it on getting the message Access is denied
after executing the sc
command. In that case open the Command Prompt (Admin) by pressing 'Windows + X' keys.
You can use PowerShell! (To start it, type powershell
at a normal command prompt.)
The Get-Service
cmdlet gets a list of services, which you can filter by any property. For example, this gets a list of disabled services:
Get-Service | ? {$_.StartType -eq 'Disabled'}
The Set-Service
cmdlet can set several properties of a given service, including the startup type. For example, this sets the lanmanserver
service to start automatically:
Set-Service 'lanmanserver' -StartupType Automatic
To make all currently disabled services start automatically, use this command:
Get-Service | ? {$_.StartType -eq 'Disabled'} | Set-Service -StartupType Automatic