How to escape special characters in SC Config command

RDG 21 Reputation points
2022-10-23T15:00:19.63+00:00

Hi Everyone,

I'm trying to log on in one service with a specific user and password so I run this command in command line:

SC config ServiceName type= "own" obj= "user" Password= "password"

Supposedly everything is ok because the message I get is:

[SC] ChangeServiceConfig SUCCESS

But When I try to run the service again once I change the configuration in command line I get this:

SC start ServiceName

[SC] StartService FAILED 1069:

The service did not start due to a logon failure.

I think the problem is the password which contains special characters like %\"@: so I don't know how can I escape in order the command works correctly.

If somebody knows How Can I fix it that would be great.

Thanks a lot

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,906 Reputation points
    2022-10-24T02:13:22.663+00:00

    Has the user account (obj= "user") in the SC.exe ever been used to log on as a service before? If not, grant that user the "Log on as a service" right.

    The only character in your double-quoted password that might, I think, need to be escaped is the "%". If it needs to be escaped try doubling it, or maybe using a "^". So, your password may have to become p8tAGO:bn4P]\b@%%. or p8tAGO:bn4P]\b@^%

    I don't believe that's a PowerShell thing, though. SC.exe (like many DOS exe's) may be handling the parameter values all by itself, even after all the other quoting and special character escaping that the shell handles.

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,906 Reputation points
    2022-10-23T15:51:55.307+00:00

    The only thing I see in the characters you listed is the doublequote. You escape that like this:

    SC config ServiceName type= "own" obj= "user" Password= "passw`"ord"  
    

    Or like this, by using singlequotes to surround the literal:

    SC config ServiceName type= "own" obj= "user" Password= 'passw"ord'  
    

    Since you didn't have a problem setting the password I don't think that's where your problem lies. Did you change the password of the user to agree with the password you configured the service to run as?

    0 comments No comments

  2. RDG 21 Reputation points
    2022-10-24T01:08:10.763+00:00

    Hi Again,

    The password was changed and now contains :]@%

    Do you know How to escape any of them please?

    Thanks a lor for your previous answer, really appreciated

    0 comments No comments

  3. RDG 21 Reputation points
    2022-10-24T01:12:17.06+00:00

    And also backslash \

    Thanks

    0 comments No comments

  4. RDG 21 Reputation points
    2022-10-24T01:19:36.133+00:00

    Password could be this one:

    p8tAGO:bn4P]\b@%

    0 comments No comments