We help IT Professionals succeed at work.

Escaping a password when calling "sc config"

Medium Priority
3,052 Views
Last Modified: 2013-12-03
One of our users has a password that begins with a dollar sign ($), and it's causing problems when using it to set the username/password a service should be run as.

Here's a (redacted) example.  When I run the "sc config" command, it correctly sets the service's username to "james@ultrabacon.com", but the password isn't set properly, so the service cannot be started.  If I use the Services GUI to enter the same password, though, I'm able to start the service.

Is there a way to escape the password string so that special characters are ignored?
sc config serviceName start= auto obj= james@ultrabacon.com password= $ser1nade

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Put the password in double quotes:

sc config serviceName start= auto obj= james@ultrabacon.com password= "$ser1nade"

Open in new window

Author

Commented:
I tried that, but it still has problems.  Tried using a caret (^) and backslash (\) as escape characters, as well, but to no avail.
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
Are you sure that it's the "$"  at the beginning? I've set the password for a service account to something starting with a "$", and could set the password (and start the service) without problems using sc.
Any one of these characters can cause problems in a batch script or from the command line: ^ % & ( ) < > |
You can try if the password works by simply adding an "echo" in front of sc; if the password is listed correctly in the output generated, it should work for setting it as well.
The account has "Logon as service" user right? This right will automatically be given if you change the account in the GUI, but not using sc.exe.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Looks like encapsulating the [obj] value in quotes and removing the quotes around the [password] value fixed it.  Still not sure exactly why this happened, but I'm happy it was solved.
sc config serviceName start= auto obj= "james@ultrabacon.com" password= $ser1nade

Open in new window

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.