Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 308
Gal Shadeck Avatar asked Jun 08 '09 19:06

Gal Shadeck


People also ask

How do I change my Windows Service password?

To configure this, Navigate to Admin >> Settings >> General Settinngs. In the UI that opens, select Password Reset from the options on the left hand side. Click the checkbox Wait for a specified time period (in seconds) between stopping and starting the services.

How do I change users in CMD?

Try this: Navigate to c:\windows\system32. Enter the following command: runas /user:computer_name\account_name explorer.exe.

Where are Windows service credentials stored?

First of all, credentials for service accounts are stored in the local registry, as what's called "LSA Secrets" in the registry key HKEY_LOCAL_MACHINE/Security/Policy/Secrets. Because the service needs to read the actual password to login as the service account, that password is in the registry in clear-text.


2 Answers

sc.exe config "Service Name" obj= "DOMAIN\User" password= "password" type= own 

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

@MattT points out that on Windows Server 2008R2 you have to add type= own, but prior to that version it isn't necessary.

In PowerShell 3+, you can avoid escaping the arguments with the stop-parsing symbol: --%

sc.exe --% config "Service Name" obj= "DOMAIN\User" password= "password" type= own 
like image 183
brianary Avatar answered Sep 29 '22 19:09

brianary


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

like image 33
Jesse Weigert Avatar answered Sep 29 '22 19:09

Jesse Weigert