I would like to save a vbs file in a batch file like this:
echo set shell = createobject("wscript.shell")
wscript.sleep(1000)
shell.sendkeys("blablabla")
Shell.SendKeys "{Enter}"
wscript.sleep(1000) >"c:\folder\blablabla.vbs"
but the batch file doesn't work. If I do it like this(If I type the vbs code in one line):
echo set shell = createobject("wscript.shell") wscript.sleep(1000) shell.sendkeys("blablabla") Shell.SendKeys "{Enter}" wscript.sleep(1000) >"c:\folder\blablabla.vbs"
then the vbs file doesn't work. So my question is: how can I save the vbs file correctly, without making the batch file think that I want him to do multiple commands.
Agroupate the commands you wanr using the agroupation operators
()
and escape conflictiveBatch
operators in code using^
.To concatenate instructions in
VBScript
you need to use the:
operator, then an all-in-one line code should look like this:Here is another method. The
:::
is harmless in VBS, and works like a comment in batch. What makes it particularly nice is you don't have to worry about escaping any of the VBS code.I chose
:::
because it is unlikely to appear elsewhere in your batch script; whereas:
is used in batch labels, and::
is frequently used as a batch comment.Here are some more options that only require a string to mark the beginning of the VBS, so they may be easier to write if dealing with a significant amount of VBS. Be sure to have
exit /b
before the VBS.This second option is slower, and it will strip empty lines as currently written.
This third option is fast, but MORE will convert tabs into a string of spaces.