Here's an example with the technique(hack) invented by the dostips forums' user Liviu:
@echo off
echo Printed by CMD.EXE
cscript //nologo "%~f0?.wsf" //job:JS //job:VBS
exit /b %errorlevel%
----END OF BATCH CODE---
<package>
<job id="JS">
<script language="VBScript">
WScript.Echo("Printed by VBScript"):
</script>
</job>
<job id="VBS">
<script language="JScript">
WScript.Echo("Printed by JScript");
</script>
</job>
</package>
As running wsf
file with windows script host is extension sensitive you can run a file with any extension by adding ?.wsf
at the end of the file (which is the core of the hack). While the Liviu's example is probably more robust the above code is more simplified version. As wsh does not care much about the things outside the <package>
node you are not obligated to put everything in xml comments. Though it's to be careful with redirection symbols (<
and >
)