WScript SendKeys 转义特殊字符

WScript SendKeys escape special characters

我想制作一个提示用户默认值的 bat 文件。还好,我找到了CScript方式

但是我对像 pharanteses 这样的特殊字符有疑问..

bat文件是

set "mysql_password="
title MyUniqueTitle
CScript //E:JScript //Nologo "%cscripts_path%\sendkeys.js" "MyUniqueTitle" "&GS)u**,o7,r"
set /p "mysql_password=> Enter new MySQL Password: "

和sendkeys.js

try
{
    var WshShell = WScript.CreateObject('WScript.Shell');
    var Title = WScript.Arguments.Item(0);
    var Message = WScript.Arguments.Item(1);
    WshShell.AppActivate(Title);
    WshShell.SendKeys(Message)
    WScript.Quit(0);
}
catch(e)
{
    WScript.Echo(e);
    WScript.Quit(1);
}
WScript.Quit(2);

问题出在 WshShell.SendKeys(Message) 上,这里我应该使用转义函数,将大括号放在特殊字符上。

有谁知道从 SendKeys 中转义 Message 代码的方法吗?

谢谢!

先在批处理文件中用字符串替换转义特殊字符即可。

@if (@CodeSection == @Batch) @then

@echo off &setlocal enabledelayedexpansion

set "password=&GS)+[]+u**,o7,r"

SET "password=!password:)={)}!"
SET "password=!password:+={+}!"
SET "password=!password:[={[}!"
SET "password=!password:]={]}!"

rem Enter the prefill value
CScript //nologo //E:JScript "%~F0" "!password!"
rem Read the variable
echo -----------------------------------------------------------
set /P "password=Please enter your password: "
echo password=!password!
pause
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));