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...