Search code examples
batch-filevbscripttelnet

Having problem using an operator(%) as a string


I have a batch file which runs the vbscript for the Telnet:

Option explicit
Dim oShell, str
set oShell = Wscript.CreateObject("WScript.Shell")
oShell.Sendkeys "o confidential ip~"
WScript.Sleep 1000
str = "\%"
oShell.Sendkeys "E" & str & ".~"
WScript.Sleep 1000
oShell.Sendkeys ".%c13,0;0.3.1%y~"
WScript.Sleep 1000
oShell.Sendkeys "~"

When I run the batch file, the % character goes away and executes only

E.
.c13,0;0.3.1y

I want % to be used as a string after connecting to the telnet. I tried everything, it didn't seem to work.

Please help


Solution

  • As stated here:

    The plus sign "+", caret "^", percent sign "%", tilde "~", and parentheses "()" all have special meanings and must be enclosed within braces "{}".

    So you should take care if, for example a % should be used as a literal in a 'sendkey' string, to enclose it with braces like {%}.