Error sending (character with sendkeys in vbscript

I get the following error when I try to send send the character "(" or ")" using SendKeys. In my vbscript.

Invalid procedure call or argument

My script:

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

It does not send "(" and ")" when I try to send them before the loop, but it does not show any errors and continues until it encounters another "(" character "and stops with the error.

0
source share
1 answer

Brackets are considered a special character and must be surrounded by braces. See the link for more details.

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
+2
source

All Articles