Running a .bat file that exectutes a program and passes it a password that has an exclamation point


I need help figuring out how to pass a password with an exclamation point to a program from inside a batch file.  I have tried multiple methods.  Like using SETLOCAL EnableDelayedExpansion before the line that executes the program passing it the password.

Neither of these works:

This alone:

deployssrsreports.exe "Doesn!tWork"

And also this:

SETLOCAL EnableDelayedExpansion
deployssrsreports.exe "Doesn!tWork"

When logged, with an echo, the password has no exclamation point.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Can you change the password? How about passing 2 !!
ChrisWibleAuthor Commented:
I can't change the password.  I really want my scripts to not care what the password is.  Thanks for the response, though.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Delayed Expansion is the reason for that, so enabling it will not change anything ;-). You need to disable it:
   setlocal DisableDelayedExpansion
but that might not work either whenever a subshell is called. For this purpose it should work.
Ohter than that you have to prefix %!&() and some more with a caret: ^! for example.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Steve KnightIT ConsultancyCommented:
You can do something like this with ^ to escape the ! as long as it is in quotes.

echo "^!DDLS"


SETLOCAL EnableDelayedExpansion
deployssrsreports.exe "Doesn^!tWork"

Open in new window

[Edit: Sorry Qlemo, duplicated your comment there, doing other things at the same time]
Joe Winograd, Fellow&MVEDeveloperCommented:
With EnableDelayedExpansion, you can send it with:


Regards, Joe
ChrisWibleAuthor Commented:
Excellent!  I am toooo overworked!  I should have seen this!  Thank you so much!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.