@echo off setLocal enableDelayedExpansion for /L %%I in (1,1,10) do @( set "dir=!tmp!\%~n0-tmp-!RANDOM!" mkdir "!dir!" 2>nul && goto unpack ) echo %~nx0: Can't make !dir!>&2 goto :eof :unpack set script=nul set main_cmd=rem set empty= for /f "usebackq skip=30 delims=" %%L in ("%~f0") do ( for /f "tokens=1-3" %%A in ("%%L") do ( if "%%A" == "::begin" ( set script="!dir!\%%B" set name=%%B set !name:.=_!=!script! set empty=%%C ) else if "%%A" == "::paste" ( type "!dir!\%%B" >>!script! ) else if "%%A" == "!empty!" ( echo.>>!script! ) else echo.%%L>>!script! ) ) call !main_cmd! %* & rmdir /s /q "%dir%" goto :eof ::begin invoke.txt js cscript.exe /Nologo ps1 powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File vbs cscript.exe /Nologo ::begin main.cmd for /f "usebackq tokens=1*" %%A in (!invoke_txt!) do set "%%A=%%B" set break=goto :eof for %%P in (help cmd js ps1 vbs all) do if "%1" == "%%P" goto %%P type %usage_txt% %break% :help type %help_txt% %break% :all set break= :cmd call %hello_cmd% %* %break% :js %js% %hello_js% %* %break% :ps1 %ps1% %hello_ps1% %* %break% :vbs %vbs% %hello_vbs% %* ::begin helpers.js // Make working with WSH collections a little less tedious. function items(coll) { var result = []; for (var i = 0; i < coll.length; ++i) { result.push(coll.item(i)); } return result; } ::begin hello.cmd echo Hello from hello.cmd. Args: %* ::begin hello.js ::paste helpers.js WScript.Echo('Hello from hello.js. Args: ' + items(WScript.Arguments).join(', ')); ::begin hello.ps1 Write-Host "Hello from hello.ps1. Args: $($args -join ', ')" cscript.exe /Nologo $env:hello_js 'Called from PowerShell' @args ::begin hello.vbs WScript.Echo "Hello from hello.vbs. Args:" for each arg in WScript.Arguments WScript.Echo arg next ::begin usage.txt Usage: glue.cmd help|cmd|js|ps1|vbs|all [ARGS] ::begin help.txt - ::paste usage.txt - Glue.cmd is a stub showing a way to combine several Windows scripting languages inside a single script. To make it useful you need to replace the sample script fragments inside it with your own. - It works by unpacking itself into separate scripts inside a temporary folder, defining environment variables allowing for easy invocation of each of these, passing all its own arguments to the unpacked main.cmd, then removing the temp folder when main.cmd returns. - The original motivation was the lack of an easy way to make PowerShell scripts that users can launch with a simple double-click or pass files to with drag and drop. Glue.cmd does that and also lets you use a mixture of Cmd, JScript and/or VBScript as well. It can easily be extended for other scripting languages and contains no XML. - Take a look at the code from "::begin invoke.txt" downward and you'll soon work out how to adapt it for your own purposes. - Stephen Thomas Last updated 31-Dec-2013 - This is free software. Do whatever you like with it except hold me accountable for any grief it causes you.