3

I am trying to create a batch file that will create a VBScript. I tried doing something like:

echo somescripthere & morehere , andhere >> hello.vbs
pause (for debugging)

But when I run the batch file it responds with

"somescripthere" is not recognized as an internal or external command,
operable program or batch file.
"morehere" is not recognized as an internal or external command,
operable program or batch file.
"andhere" is not recognized as an internal or external command,
operable program or batch file.

Anyone know what is causing this and how I could fix it? I'm not that good at coding and even worse at VBScript.

5
  • The script is complaining about somescripthere and not morehere? Commented Sep 2, 2017 at 16:46
  • It complains about all of them, in sequence. Commented Sep 2, 2017 at 17:06
  • Why don't you attempt it with real world vbscript commands. Obfuscating an example like this is pointless. Commented Sep 2, 2017 at 17:31
  • That output doesn't match the code you've provided. It should print the string somescripthere and then try to run morehere , andhere >> hello.vbs. Commented Sep 2, 2017 at 17:32
  • 1
    You could do a Batch + VBScript hybrid script without needing to echo out to a separate .vbs file. See this example. Commented Sep 2, 2017 at 23:09

2 Answers 2

1

Here is an example showing you how to create a vbscript from a batch file and execute it with cscript engine :

@echo off
Title Typewriter with speaking voice by Hackoo 2017
Color 0A & Mode con cols=70 lines=3
::*************************************************
Rem Just creating a vbscript file 
Rem to be executed with cscript engine
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 150
echo For x = 1 to intTextLen
echo     strTempText = Mid(strText,x,1^)
echo     WScript.StdOut.Write strTempText
echo     WScript.Sleep intPause
echo Next
echo Set Voice=CreateObject("SAPI.SpVoice"^)
echo voice.speak strText
)>%tmp%\%~n0.vbs
::*************************************************
:Main
set Msg="This is only a testing string to see if my script really works or not?"
Call :Typewriter %Msg%
set Msg="      This a message from a vbscript created from a batch file !"
Call :Typewriter %Msg%
set Msg="         I want to say Hello for everybody on Stackoverflow !"
Call :Typewriter %Msg%
Timeout /t 3 /nobreak>nul
if exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs" 
Exit
::*********************************************************************
:TypeWriter
Cls
echo(
cscript.exe /noLogo "%tmp%\%~n0.vbs" "%~1"
exit /b
::*********************************************************************

Another example to listen to a radio station online with vbscript and batch

@echo off
Title Listen to the music with batch and vbscript
mode con cols=60 lines=3 & color 9E
echo.
Echo   To stop the music just close this window 
set "file=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx"
set "vbsfile=%tmp%\%~n0.vbs"
( 
    echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
    echo Sound.URL = "%file%"
    echo Sound.Controls.play
    echo do while Sound.currentmedia.duration = 0
    echo wscript.sleep 100
    echo loop
    echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000
)>%vbsfile%
cscript /nologo %vbsfile%
Sign up to request clarification or add additional context in comments.

Comments

0

You should add escape character before "&"

echo somescripthere ^& morehere , andhere >> hello.vbs

Comments