windows NET START <SERVICE> - 如何/从哪里获取服务名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7172276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NET START <SERVICE> - how/where to get the service name?
提问by gaffcz
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
".
问题是我不知道服务的名称。例如,“ printer spooler
”是名称“ spooler
”。
How can I find the name for any service?
如何找到任何服务的名称?
回答by Tung
- Start → Run
- Then type:
services.msc
. - Double click on the service that you're interested in.
- 开始→运行
- 然后输入:
services.msc
。 - 双击您感兴趣的服务。
You should see:
你应该看到:
回答by Damien_The_Unbeliever
Use sc
rather than net
, since it boasts a lot more features. It was first introduced (IIRC) in Windows XP:
使用sc
而不是net
,因为它拥有更多功能。它首先在 Windows XP 中引入 (IIRC):
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
.
然后您可以在其他命令中使用该名称,例如sc start
和sc stop
。
回答by rodrigo
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.
我从注册表中得到它:HKLM\System\CurrentControlSet\Services。每个子项都是服务或驱动程序的名称。只需搜索您正在寻找的那个。
回答by Martin Lind
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:
对于有权访问 PowerShell 的系统。执行此操作的更好方法是使用 Cmdlet“Get-Service”。您可以通过键入以下内容来调用它:
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:
您在名称下获得服务名称的位置。如果您愿意,DisplayName 参数可以采用通配符。如果你想获得显示名称,你可以写:
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:
这实际上只需要检查服务是否正在运行。PowerShell 有 Cmdlet Start-Service 和 Stop-Service,它们采用参数 -Name 和 -DisplayName,因此您可以编写:
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.
在这种情况下,我使用了 PowerShell 2.0,所以我想它可以在以上任何 Windows 上运行,包括 XP。