发送时出错(在vbscript中使用sendkeys的字符

时间:2012-04-10 14:25:21

标签: vbscript

当我尝试使用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

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

1 个答案:

答案 0 :(得分:3)

括号被视为特殊字符,需要用括号括起来。有关详细信息,请参阅此link

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