windows 如何通过命令行设置windows服务用户名和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/308298/
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
how to set windows service username and password through commandline
提问by sundar venugopal
Using sccommand we can query, start , stop windows services.
For ex:
使用sc命令我们可以查询、启动、停止 Windows 服务。
例如:
sc query "windows service name"
The sc configcommand changes the configuration of the service, but I don't know how to use it.
该sc配置命令改变服务的配置,但我不知道如何使用它。
Could someone tell me how we can set the username and password for any windows service?
有人能告诉我如何为任何 Windows 服务设置用户名和密码吗?
回答by Andrew Ferrier
This works:
这有效:
sc.exe config "[servicename]" obj= "[.\username]" password= "[password]"
Where each of the [bracketed] items are replaced with the true arguments. (Keep the quotes, but don't keep the brackets.)
其中每个 [括号内] 项都替换为真实参数。(保留引号,但不要保留括号。)
Just keep in mind that:
请记住:
- The spacing in the above example matters.
obj= "foo"
is correct;obj="foo"
is not. - '.' is an alias to the local machine, you can specify a domain there (or your local computer name) if you wish.
- Passwords aren't validated until the service is started
- Quote your parameters, as above. You can sometimes get by without quotes, but good luck.
- 上面例子中的间距很重要。
obj= "foo"
是正确的;obj="foo"
不是。 - '.' 是本地机器的别名,如果您愿意,您可以在那里指定一个域(或您的本地计算机名称)。
- 在服务启动之前不会验证密码
- 引用您的参数,如上所述。有时你可以不加引号,但祝你好运。
回答by Alberto Dallagiacoma
In PowerShell, the "sc" command is an alias for the Set-Content cmdlet. You can workaround this using the following syntax:
在 PowerShell 中,“sc”命令是 Set-Content cmdlet 的别名。您可以使用以下语法解决此问题:
sc.exe config Service obj= user password= pass
Specyfying the .exe extension, PowerShell bypasses the alias lookup.
指定 .exe 扩展名后,PowerShell 会绕过别名查找。
HTH
HTH