Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何使用sendkeys写入传递的变量_Batch File_Vbscript - Fatal编程技术网

Batch file 如何使用sendkeys写入传递的变量

Batch file 如何使用sendkeys写入传递的变量,batch-file,vbscript,Batch File,Vbscript,简要说明:尝试使用sendkeys从批处理文件的输出中键入两个变量/键 我不断发现语法错误或下标错误 通过以下方式从批处理脚本传递两个变量: cscript //nologo sendKeys.vbs !config! !arguments! rem Yes, both variables are defined, and delayed expansion in enabled. 我想把它们放进sendkeys的尝试似乎不起作用。我不熟悉VBS VBScript: Set WshShell

简要说明:尝试使用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

.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解决现实世界问题的方法。

我向其发送垃圾邮件的应用程序不支持向其传递变量,除了这两种语言之外,我什么都不知道。谢谢你的回答,很抱歉这么简单。