3 回答
TA贡献1951条经验 获得超3个赞
<SUB>
注 - <SUB>
::<sub>echo This will execute in batch, but it will fail as vbs.rem<SUB>echo This will execute in batch, and it is also a valid vbs comment::'<SUB>echo This will execute in batch and it is also a valid vbs comment
rem<SUB>
::'<SUB>
EXIT
EXIT /B
:'Label
<SUB>
::'<SUB>@cscript //nologo //e:vbscript "%~f0" & exit /bWScript.Echo "Example of a hybrid VBS / batch file"
更新2012-04-15
&
, |
, <
, >
REM
REM.
REM.
REM^
REM^ &
REM &
ECHO OFF
.
rem^ &@cscript //nologo //e:vbscript "%~f0" & exit /bWScript.Echo "Example of a hybrid VBS / batch file"
::' VBS/Batch Hybrid::' --- Batch portion ---------rem^ &@echo offrem^ &call :'subrem^ &exit /b:'subrem^ &echo begin batchrem^ &cscript //nologo //e:vbscript "%~f0"rem^ &echo end batchrem^ &exit /b'----- VBS portion ------------wscript.echo "begin VBS"wscript.echo "end VBS"'wscript.quit(0)
更新2012-12-17
""
""""
@echo off setlocal:: Define simple batch "macros" to implement VBS within batchset "vbsBegin=mshta vbscript:Execute("createobject(""scripting.filesystemobject"")" set "vbsBegin=%vbsBegin%.GetStandardStream(1).write(" set ^"vbsEnd=):close"^)":: Get yesterday's datefor /f %%Y in ('%vbsBegin% date-1 %vbsEnd%') do set Yesterday=%%Yset Yesterday pause echo(:: Get pifor /f %%P in ('%vbsBegin% 4*atn(1) %vbsEnd%') do set PI=%%Pset PI pause echo(set "var=name=value"echo Before - %var%:: Replace =for /f "delims=" %%S in ( '%vbsBegin% replace(""%var%"",""="","": "") %vbsEnd%') do set "var=%%S"echo After - %var%pause echo(echo Extended ASCII:for /l %%N in (0,1,255) do ( %= Get extended ASCII char, except can't work for 0x00, 0x0A. =% %= Quotes are only needed for 0x0D =% %= Enclosing string quote must be coded as "" =% %= Internal string quote must be coded as """" =% for /f delims^=^ eol^= %%C in ( '%vbsBegin% """"""""+chr(%%N)+"""""""" %vbsEnd%' ) do set "char.%%N=%%~C" %= Display result =% if defined char.%%N ( setlocal enableDelayedExpansion echo( %%N: [ !char.%%N! ] endlocal ) else echo( %%N: Doesn't work :()pause echo(:: Executing the mini VBS script directly like the commented code below :: will not work because mshta fails unless stdout has been redirected:: or piped.:::: %vbsBegin% ""Hello world"" %vbsEnd%:::: But this works because output has been piped%vbsBegin% ""Hello world"" %vbsEnd% | findstr "^"pause
2014-04-27
<!-- : Begin batch script@echo off cscript //nologo "%~f0?.wsf"exit /b----- Begin wsf script ---><job><script language="VBScript"> WScript.Echo "VBScript output called by batch"</script></job>
-->
.
</script>
.
"%~f0?.wsf"
"%~f0"
?.wsf
<!-- : Begin batch script@echo off echo batch output cscript //nologo "%~f0?.wsf" //job:JS cscript //nologo "%~f0?.wsf" //job:VBSexit /b----- Begin wsf script ---><package> <job id="JS"> <script language="VBScript"> sub vbsEcho() WScript.Echo "VBScript output called by JScript called by batch" end sub </script> <script language="JScript"> WScript.Echo("JScript output called by batch"); vbsEcho(); </script> </job> <job id="VBS"> <script language="JScript"> function jsEcho() { WScript.Echo("JScript output called by VBScript called by batch"); } </script> <script language="VBScript"> WScript.Echo "VBScript output called by batch" call jsEcho </script> </job></package>
添加回答
举报