5

Is it possible to embed VBScript within a batch file?

I currently have a .CMD file that calls a .VBS file using

cscript //NoLogo MyScript.vbs

but I'd prefer to distribute just a single .CMD file.


EDIT: There is a similar question with answers on how to do this without generating an intermediate file at all: Is it possible to embed and execute VBScript within a batch file without using a temporary file?

Community
  • 1
  • 1
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
  • Found an interesting hack where a batch script scans itself for labels (which are the VBScript) and writes it out to a new VBS file, which it executes http://www.computerhope.com/forum/index.php?topic=103686.0 – sourcenouveau Oct 27 '10 at 21:15
  • Possible duplicate of [Is it possible to embed and execute VBScript within a batch file without using a temporary file?](http://stackoverflow.com/questions/9074476/is-it-possible-to-embed-and-execute-vbscript-within-a-batch-file-without-using-a) – aschipfl Oct 06 '16 at 12:20

1 Answers1

8

http://www.computerhope.com/forum/index.php?topic=103686.0

@echo off
echo This is batch
:wscript.echo "This VBScript"
:wscript.echo "Today is " & day(date) & "-" & month(date) & "-" & year(date)
findstr "^:" "%~sf0">temp.vbs & cscript //nologo temp.vbs & del temp.vbs
echo This is batch again
drudge
  • 35,471
  • 7
  • 34
  • 45