1

当我尝试使用 SendKeys 发送“(”或“)”字符时出现以下错误。在我的 vbscript 中。

Invalid procedure call or argument

我的脚本:

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 100
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\Administrator\Desktop\readme.txt", 1)
Wshshell.SendKeys "!@#$%^&*()"
Do Until objFile.AtEndOfStream
    strCharacters = objFile.Read(1)

    WshShell.SendKeys strCharacters
Loop

当我尝试在循环之前发送它们时它不会发送“(”和“)”但没有显示错误并继续直到它遇到另一个“(”字符并因错误而停止。

4

1 回答 1

4

括号被认为是一个特殊字符,需要用大括号括起来。有关更多详细信息,请参阅此链接

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 100
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\Administrator\Desktop\readme.txt", 1)
Wshshell.SendKeys "!@#$%^&*{(}{)}"
Do Until objFile.AtEndOfStream
    strCharacters = objFile.Read(1)

    WshShell.SendKeys strCharacters
Loop
于 2012-04-10T14:48:18.340 回答