Reputation: 3479
I need to create a common script to restart service:
net stop <service>
net start <service>
Problem is that I don't know the name of the service.
For example for "printer spooler
" is the name "spooler
".
How can I find the name for any service?
Upvotes: 20
Views: 62464
Reputation: 5444
services.msc
.You should see:
Upvotes: 29
Reputation: 71
For systems that have access to PowerShell. A better way to do this is with the Cmdlet "Get-Service". You can invoke it by typing:
Get-Service -DisplayName "Print Spooler"
Which will return:
Status Name DisplayName
------ ---- -----------
Running Spooler Print Spooler
Where you get the name of the service under Name. The DisplayName parameter can take wild cards if you like. If you want to get the Display name you can write:
Get-Service -Name spooler
Which would return the same table as above. You can also write:
(Get-Service -DisplayName "Print Spooler").Name
To get just the name (avoid a table).
This is really only necessary to do to check if a service is running. PowerShell have the Cmdlet Start-Service and Stop-Service which takes the parameter -Name and -DisplayName so you could write:
Start-Service -DisplayName "Print Spooler"
Stop-Service -DisplayName "Print Spooler"
To start and stop the service.
In this case I've used PowerShell 2.0 so I guess it will work on any Windows above and including XP.
Upvotes: 7
Reputation: 239784
Use sc
rather than net
, since it boasts a lot more features. It was first introduced (IIRC) in Windows XP:
sc GetKeyName "printer spooler"
should print something like:
[SC] GetServiceKeyName SUCCESS Name = Spooler
And you can then use that name in other commands, like sc start
and sc stop
.
Upvotes: 10
Reputation: 98496
I get that from the registry: HKLM\System\CurrentControlSet\Services. Each subkey is the name of a service or driver. Just search for the one you are looking for.
Upvotes: 7