WScript SendKeys转义特殊字符
问题描述:
我想制作一个提示用户使用默认值的bat文件。没关系,我找到了一种CScript方式。WScript SendKeys转义特殊字符
但是我有特殊字符,如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(消息) ,在这里我应该使用一个逃生功能,把镯子放入特殊字符中。
有谁知道从SendKeys转义邮件代码的方法?
谢谢!
答
只需在批处理文件中首先使用字符串替换特殊字符即可。
@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));
批转义字符是'^'(除非你转义'%',那么你使用第二个转义它)。 – SomethingDark
您的意思是?如果我添加)像WshShell.SendKeys(&GS {)} u **,o7,r)这样的大括号将会像它应该那样工作。因此需要一种使用SendKey方法的方法来使用转义规则。 – oriceon
以下是特殊字符的有效代码:http://orporate.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx –