Escaping a password when calling "sc config"

Posted on 2009-02-16
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 "", 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= password= $ser1nade

Open in new window

Question by:deathtospam
    LVL 82

    Expert Comment

    Put the password in double quotes:

    sc config serviceName start= auto obj= password= "$ser1nade"

    Open in new window

    LVL 9

    Author Comment

    I tried that, but it still has problems.  Tried using a caret (^) and backslash (\) as escape characters, as well, but to no avail.
    LVL 82

    Accepted Solution

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

    Author Comment

    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= "" password= $ser1nade

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now