0

I'm trying to change some service logon on windows 10 using batch file.

My code is:

set service_name="some service"
set user_password=Pa$$w0rd

@echo stop %service_name%
sc stop %service_name%
timeout 5
@echo Config %service_name%
sc config %service_name% type= own obj= "%userdomain%\%USERNAME%" password= %user_password%
timeout 5
@echo Start %service_name%
sc start %service_name%

I'm successfully stops and changes the service (output: [SC] ChangeServiceConfig SUCCESS ), but when I'm trying to restart the service I'm getting this error:

[SC] StartService FAILED 1069: The service did not start due to a logon failure.

If I'm changing the password manually I can restart the service, so I think its something has to do with the spacial chars in my password, the password I'm using is: Pa$$w0rd. I already read some answers (Batch character escaping, Special Characters in Batch File) but it's seems that there is no escape chars for $.

Can you help me find the escape chars for $ or to point my error?

Thx!

Update:

As suggested in the commands I tried set the password variable as follow:

@set "user_password=Pa$$w0rd"

and then use the variable with double quotes on the sc config, but got the same error...

DavidDr90
  • 559
  • 5
  • 20
  • 1
    If you were to use the correct syntax when `set`ting your variables, i.e. `Set "user_password=Pa$$w0rd"`, you'd be able to doublequote `%user_password%` in the same manner as you did with the Account Name to `obj`, i.e. `password= "%user_password%"` – Compo Apr 17 '19 at 13:15
  • @Compo and that would solve the logon error? – DavidDr90 Apr 17 '19 at 13:16
  • @Compo did not work... – DavidDr90 Apr 17 '19 at 14:33
  • @Compo thanks for your command. I update the original question. The password is `Pa$$w0rd`, and as I mentioned in the question the spacial character is `$` – DavidDr90 Apr 17 '19 at 14:42
  • The `$` isn't a special character as far as the batch file is concerned anyhow, so now that we've 'almost' negated the issue being with the entered password, you need to determine whether that user has sufficient permissions to actually run the service on that system. – Compo Apr 17 '19 at 14:45
  • @Compo If I'm manually enter the password using the services window I can restart the service, so I think it's mean the user have the right permissions – DavidDr90 Apr 17 '19 at 14:50

0 Answers0