Batch file echo to .vbs VB script?

Microsoft Windows xp professional w/serv...
July 1, 2011 at 09:00:30
Specs: Windows XP, 2g
I would like to make a batch file that creates a vb script if it is not found .example:
=========
if not exist %temp%\bob.vbs echo (
VBCODE
VBCODE
VBCODE
VBCODE
) > %temp%\bob.vbs
cscript //nologo %temp%\bob.vbs
=========

reason being, I would like to minimize file dependecies so If I need to send the script to a co-worker to use, i wont have to send a zip file with a batch file and 4 diffrent vbscripts. It would be 1 batch file that would check if the scripts exsisted and if not echo them to a file then continue running the batch file.

Would this be possible?


See More: Batch file echo to .vbs VB script?

Report •


#1
July 1, 2011 at 15:35:58
Yes, but your coding should be amended to:

if not exist %temp%\bob.vbs (
echo VBCODE
echo VBCODE
echo VBCODE
echo VBCODE
) > %temp%\bob.vbs
.
.
.
etc...


Please come back & tell us if your problem is resolved.


Report •

#2
July 2, 2011 at 10:23:37
Wahine's suggestion is absolutely right but I want to point out the following notes since I use this method to set up scripts blended with batch and vbs and faced some issues.

The main problem is batch syntax does not allow coding echo with brackets inside a sequence enclosed by brackets, e.g.

(
...
echo this is not allowed (any string)
...
)

So since VBScript uses a lot of brackets better you code

if not exist %temp%\bob.vbs call :VBSBOB > %temp%\bob.vbs
cscript //nologo %temp%\bob.vbs

if not exist %temp%\bob2.vbs call :VBSBOB2 > %temp%\bob2.vbs
cscript //nologo %temp%\bob2.vbs
...
...
goto :EOF [Returm to OS]

:VBSBOB
  echo.VBCODE
  echo.VBCODE
  echo.VBCODE
  echo.VBCODE
goto :EOF [End of BOB.VBS]

:VBSBOB2
...
...
goto :EOF [End of BOB2.VBS]

if you want to run the VBScripts concurrently use start "" cscript otherwise the batch waits until the VBScript is terminated. The label :EOF must not be delared since it is the built-in go-back code for NT batch.

Report •

#3
July 2, 2011 at 14:34:34
@Ivo - The main problem is batch syntax does not allow coding echo with brackets inside a sequence enclosed by brackets, e.g.

(
...
echo this is not allowed (any string)
...
)

Sorry Ivo, I must query this. Provided that closing brackets ')' in the echo command lines are Escaped '^' I have no problem with echoing bracketed items. If any closing bracket is not Escaped it is treated as the closing bracket for the entire sequence rather than a literal.

Please would you like to try the script below and let me know how I misunderstand you?:

@echo off
cls
setlocal

(
echo vbcode (something here^) and (((another thing^)^)^) (1^)
echo vbcode (something else^)
echo vbcode (last thing here^) not this (trouble^) (^) 1 (end^)
)>%temp%\vbs.vbs

type %temp%\vbs.vbs


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
July 2, 2011 at 14:54:39
@Wahine

I agree with your style of coding, i.e. escaping with ^ the right bracket on echo command line, but it is just that I want to avoid. Just to copy and paste the VBScript without the need of escaping the right brackets only prefixing each line with echo. Using my way I "imported" directly huge VBScripts into batch without editing their command structure.


Report •

#5
July 2, 2011 at 15:45:12
Thank you Ivo - I now understand your methodology.


Please come back & tell us if your problem is resolved.


Report •


Ask Question