Escape exclamation mark in batch file

Viewed 2442

I got a simple code to connect to remote server. For some reason, it keep asking for password even when i already gave it in the code. The password include exclamation mark, tried to escape it with \ / " " ' ' but none of them helped me.

The code:

@echo off

cmdkey /generic:server /user:user /pass:'Aa123456!' 
mstsc.exe /v:server

exit

Didn't gave the real server and user of course, but thats the password im using.

Could someone help me?

1 Answers

The below batch log in to remote desktop using the credentials provided.

Save it as RDPLogin.bat (edit credentials as required)

use ^ for escape characters (for example)

@echo off
::Server Address/IP
set mysrvad=xyz.myrdp.com
::Server User ID
set mysrvid=user
::Server User Password
set mysrvpswd='Aa123456^!'

cmdkey /generic:%mysrvad% /user:%mysrvid% /pass:%mysrvpswd%
cls
mstsc.exe /v:%mysrvad%
exit
Related