Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SC.exe to set service credentials password fails

I know this question has been asked in the past, but a satisfactory answer has not been provided.

I am using the SC command to config the credentials for a service.

SC.exe config "SERVICE NAME" obj= "domain\user" password= "password"

This completes successfully, but when I start the service, it fails to perform the login.
[NET START "service name"]

If I manually update ONLY the password from the services.msc, then when I start the service it works fine.

I have hundreds of servers to update this change occurs in the middle of a deployment, so manual intervention is NOT an option.

I have tried using the config to update the login account and then another config command for the password.

From all accounts, the SC.exe does not work for passwords and Microsoft has NO help.

IDEAS?

like image 296
Grayson Avatar asked Jan 18 '13 22:01

Grayson


People also ask

What is SC exe used for?

The Windows SDK contains a command-line utility, Sc.exe, that can be used to control a service. Its commands correspond to the functions provided by the SCM.

What is the sc config command?

Specifies a name of an account in which a service will run, or specifies a name of the Windows driver object in which the driver will run. The default setting is LocalSystem.

Where is SC exe located?

The sc.exe command comes with Windows XP and is in the system32 subdirectory of the Windows installation directory (usually either C:\windows\system32 or C:\winnt\system32).


2 Answers

When you configure a service to run under a specific account via the normal route from the service properties windows automatically grants the account the log in as service right. When you use sc.exe you also have to grant the user the log on as service right.

Log On As Service Right

like image 163
Rich K Avatar answered Sep 22 '22 19:09

Rich K


Besides stopping the service before making the changes, and granting the user permission to logon as a service, I also had to add the type= own parameter, otherwise it would fail with:

[SC] ChangeServiceConfig FAILED 87:

The parameter is incorrect

So this is the command that worked:

SC.EXE config "ServiceName" type= own obj= "domain\user" password= "password"

It even worked with special characters in the password, given I had the password between double brackets.

like image 32
ericbn Avatar answered Sep 18 '22 19:09

ericbn