【发布时间】:2015-11-04 22:36:57
【问题描述】:
我想制作一个 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 中转义消息代码的方法?
谢谢!
【问题讨论】:
-
批量转义字符为
^(除非您要转义%,否则您使用第二个转义字符)。 -
什么意思?如果我在 WshShell.SendKeys(&GS{)}u**,o7,r) 等大括号中添加 ) 将正常工作。所以需要在 SendKey 方法中使用转义规则。
-
@oriceon 执行 cscript 时为什么不直接转义它。
CScript //E:JScript //Nologo "%cscripts_path%\sendkeys.js" "MyUniqueTitle" "&GS{)}u**,o7,r" -
因为它是动态密码。使用的一个是例如目的:|
标签: batch-file jscript wsh