Escaping special characters in cmd

I have a Windows .bat script in which I try to run a command with password in parameter. The password I want to be able to use is ~!@#$%^&*()_+|-=\][{}';:"/.>?,<.

From what I've read here, I should escape ^&|\<> with ^. From what I assume, I should escape " with \".

This gives me something like that:

runme.exe /password:"~!@#$%^^^&*()_+^|-=^\][{}';:\"/.^>?,^<"

But it doesn't work - my target app responds with logon failure.

How should I escape all these characters to be able to hardcode the password in my batch (ignoring the security issues by now)?


Solution 1:

Double the quote in the password and make sure the complete password is enclosed in quotes as well:

runme.exe /password:"~!@#$%%^^^&*()_+^|-=\][{}';:""/.>?,<"

Solution 2:

Give this a try, but if runme.exe's argument parser requires quotes as string encapsulators for passwords, the it's not going to work. If you need to have a quote in your password, then runme.exe needs to provide a way to escape it!

runme.exe /password:~!@#$%%^^^&*()_+^|-=\][{}';:"/.>?,<