batch create new text document with content

July 7, 2010 at 07:44:47
Specs: Windows XP
Hi, how do I let a batch file make a vbs file with a vbs script in it? Generating a text file from a batch file works fine. But there are some operators in the vbs script wich (I think) causes problems.

This is the batch file so far:
echo Set WshShell = WScript.CreateObject ("WScript.Shell")WshShell.Run ("C:\Windows\system32\cmd.exe")WScript.Sleep 400WshShell.SendKeys "tskill explorer /a"WshShell.SendKeys "{ENTER}"Set oWS = WScript.CreateObject("WScript.Shell")oWS.Run "%comspec% /c echo " & Chr(07), 0, TrueWshShell.SendKeys "exit"WshShell.SendKeys "{ENTER}"'Then' WScript.Quit > test.vbs

Thanks.


See More: batch create new text document with content

Report •


#1
July 7, 2010 at 08:47:59
For the most part, you'll need to escape the special batch characters either
using carat ^, or in the case of percent sign, doubling up: %%

This may be helpful:
Escape Chars

It can get pretty ugly trying to stuff special characters into places they
can be interpreted on the way out.

See response 20 in this thread:
compare-using-batch-script

specifically after the "REM Angry this has to happen:" statement for an example.

Insomniac at large


Report •

#2
July 8, 2010 at 01:53:21
Thanks for the links. But for some reason, it still doesn't work. I escaped every special character with ^... and % with %%. I really don't get it. It should be working!
Again, here's the batch file with escaped chars:
echo Set WshShell ^= WScript.CreateObject ("WScript.Shell")WshShell.Run ("C:\Windows\system32\cmd.exe")WScript.Sleep 400WshShell.SendKeys "tskill explorer /a"WshShell.SendKeys "{ENTER}"Set oWS ^= WScript.CreateObject("WScript.Shell")oWS.Run "%%comspec% /c echo " & Chr(07), 0, TrueWshShell.SendKeys "exit"WshShell.SendKeys "{ENTER}"'Then' WScript.Quit > test.vbs
pause

Thanks :)


Report •

#3
July 8, 2010 at 02:47:42
branic729:I escaped every special character with ^... and % with %%.

You missed some:

...
"%%comspec% /c echo " & Chr(07)
...


Also, you don't need to escape "=".


Report •

Related Solutions

#4
July 8, 2010 at 19:39:45
Not my business, so ignore at your discretion, but why do you want to "write" a vbs script out of batch, unless there is
variable data to be injected into the vbs...

Report •

#5
July 8, 2010 at 23:22:18
It's just for a small project of me. But I think I found a way that I don't need the vbs script. However, escaping characters in batch is kinda new for me. I'll experiment more, thanks.

Report •


Ask Question