简要说明:尝试使用sendkeys从批处理文件的输出中键入两个变量/键。
我不断获取语法或超出下标错误。
通过以下方式从批处理脚本传递两个变量:
cscript //nologo sendKeys.vbs !config! !arguments!
rem Yes, both variables are defined, and delayed expansion in enabled.
我尝试将它们放入sendkeys似乎不起作用。我不熟悉VBS ......
的VBScript:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 9 ' Start notepad in order to test my failure.
WScript.Sleep 500 ' Give notepad time to load
WshShell.SendKeys & WshShell.Arguments(0) ' write passed !config! variable
WshShell.SendKeys "{TAB}" ' tab key
WshShell.SendKeys & WshShell.Arguments(1) ' write passed !arguments! variable
WshShell.SendKeys "{ENTER}" ' enter key
答案 0 :(得分:2)
.Arguments属于WScript对象,而不是Shell。 &
是连接运算符,它在方法名称和第一个/唯一参数之间没有意义。所以使用
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 9 ' Start notepad in order to test my failure.
WScript.Sleep 500 ' Give notepad time to load
WshShell.SendKeys WScript.Arguments(0) ' write passed !config! variable
WshShell.SendKeys "{TAB}" ' tab key
WshShell.SendKeys WScript.Arguments(1) ' write passed !arguments! variable
WshShell.SendKeys "{ENTER}" ' enter key
或 - 更好 - 想想一种在没有SendKeys的情况下解决现实问题的方法。