使用批处理文件创建VBScript

3

我正在尝试创建一个批处理文件,以创建一个VBScript。我尝试做如下操作:

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

但是当我运行批处理文件时,它会回应:
"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.

有人知道是什么原因导致这个问题,以及我该如何解决吗?我不太擅长编码,VBScript更糟糕。


脚本抱怨的是somescripthere而不是morehere - SomethingDark
它按顺序抱怨所有这些问题。 - user8458095
为什么不尝试使用真实世界的VBScript命令来完成它。像这样混淆一个示例是毫无意义的。 - Squashman
输出结果与您提供的代码不匹配。它应该打印字符串somescripthere,然后尝试运行morehere, andhere >> hello.vbs - SomethingDark
1
你可以使用批处理加VBScript混合脚本,而不必将输出内容复制到单独的.vbs文件中。查看此示例 - rojo
2个回答

1
这里有一个示例,向您展示如何从批处理文件中创建VBScript,并使用cscript引擎执行它:
@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
::*********************************************************************

使用VBScript和批处理在线收听广播电台的另一个示例

@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%

0

你应该在"&"之前加上转义字符

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接