ilter
ilter

Reputation: 4079

How to escape the special characters in a password when using in CMD

I have this password, ;d#se#&4~75EY(H[SM"%cznGB.

I need to use this inside an automatically created command line command.

(using it for TFS Release pipeline, to create a virtual directory and this password belongs to a service user and saved in a global variable as secret input, and TFS puts that password string in doublequotes when creating the command).

Having a hard time escaping the scpecial characters in it.

What I tried so far is to escape all alphanumeric characters by ^ and escaping % and " characters by doubling them. But so far, didn't have much luck :(

The list of failed attempts are these.

;d#se#&4~75EY^(H[SM""%%cznGB

;d#se#&4~75EY(H[SM\"%%cznGB

^;d^#se^#^&4^~75EY^(H^[SM""%%cznGB

^;d^#se^#^&4^~75EY^(H^[SM\"^%cznGB

^;d^#se^#^&4^~75EY^(H^[SM\"%%cznGB

^;d^#se^#^&4^~75EY^(H^[SM""^%%cznGB

;d#se#&4~75EY(H[SM"^^^%%cznGB

;d#se#&4~75EY(H[SM"^^^^%%cznGB

;d#se#&4~75EY(H[SM^""^%%cznGB

^;d^#se^#^&4^~75EY^(H^[SM^""^%%cznGB

^;d^#se^#^&4^~75EY^(H^[SM^""%%cznGB

;d#se#&4~75EY(H[SM""%%cznGB

Can you please give me a hand finding the correct escaped string to use it in a batch or in CMD as an inline command?

Before anyone downvotes this question because I posted a password, I edited many parts of it before posting. Just saying :)

UPDATE:

As I mentioned in the question, TFS creates a command text to set the virtual folder access credentials to IIS, for a specific web application. The log shows the command text like this.

"C:\WINDOWS\system32\inetsrv\appcmd.exe" set vdir /vdir.name:"appfolder/Files" -physicalPath:"\\servername\virtualfolder" -userName:"[email protected]" -password:";d#se#&4~75EY(H[SM"%cznGB"

(I entered the password as it is, for this output)

Upvotes: 3

Views: 7922

Answers (1)

ilter
ilter

Reputation: 4079

How interesting this all character escaping thing works! I continued serching, and read everything I could find. The result is that all that should be escaped with in double quotes, are the double quotes themselves...

(correct me if there's something I am missing, that was correct for my case)

The resulting string that should be used in the TFS variable (and I tested it, it works!) is this:

;d#se#&4~75EY(H[SM""%cznGB

The only thing I added to the original password was another double quote near the double quote.

That answer certainly helped me. No wonder why experementing by yourselves preserves better than reading tons of articles :/

https://stackoverflow.com/a/15262019/2443719

Thanks to everyone who commented and left an answer to this thread.

Upvotes: 3

Related Questions