How to change user credentials of windows service

2019-01-22 06:28发布

How to change user credentials of windows service from command line?

3条回答
We Are One
2楼-- · 2019-01-22 07:08
sc.exe config "Service Name" obj= "DOMAIN\User" password= "password"

See Shortcut Setting Log-On Credentials for Windows Services » jonathanmalek.com.

@MattT points out that on Windows Server 2008R2, you also have to add type= own.

查看更多
Animai°情兽
3楼-- · 2019-01-22 07:08

I simply called WMI from powershell to do this.

$Svc = Get-WmiObject win32_service -filter "name='ServiceName'"
$Svc.Change($Null, $Null, $Null, $Null, $Null, $Null, "User", "Password")

Don't forget to restart the service afterwards:

Stop-Service -Name 'ServiceName'
Start-Service -Name 'ServiceName'

For more fun with WMI and services, see Win32_Service Class

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-22 07:09

Using WMI results in non-encrypted communication between your machine and the machine you are changing the service credentials on. So your new password can be sniffed quite easily. You just have to parse the WMI blob send over the network. By now I found no really secure way to change a service accounts password remotely with a tool.

查看更多
登录 后发表回答