本文介绍了WScript的逃脱的SendKeys特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打一个bat文件,它提示用户使用默认值。 All`s很好,我发现了一个在CScript方式。
I want to make a bat file that prompt user with a default value. All`s fine, I found a CScript way.
不过,我有一个像pharanteses ..
But i have a problem with special characters like 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
and 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(消息),在这里我应该使用放bracets特殊字符转义功能。
Problem is with WshShell.SendKeys(Message) , here i should use an escape function that put bracets to special characters..
有谁知道一种方式来逃避的SendKeys讯息code?
Does anyone know an way to escape Message code from SendKeys?
谢谢!
推荐答案
只是在批处理文件第一字符串替换逃跑的特殊字符。
Just escape the special characters with string substitution in the batch file first.
@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));
这篇关于WScript的逃脱的SendKeys特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!