Skip to content

Instantly share code, notes, and snippets.

@C0nw0nk
Created November 14, 2022 10:50
Show Gist options
  • Save C0nw0nk/27e0e8f685b4fb255f566b88b7a5e848 to your computer and use it in GitHub Desktop.
Save C0nw0nk/27e0e8f685b4fb255f566b88b7a5e848 to your computer and use it in GitHub Desktop.
hybrid batch file for running batch code vbscript and javascript all inline in command line
@if (@This==@IsBatch) @then
@echo off & setLocal EnableDelayedExpansion
:: Copyright Conor McKnight
:: https://github.com/C0nw0nk/
:: https://www.facebook.com/C0nw0nk
:: Hybrid batch file for running inline batch code, VBScript and Javascript from the same .cmd or .bat file
set site="https://checkip.amazonaws.com/"
::Start Javascript Execution function and args
for /f "tokens=*" %%a in ('cscript //nologo //E:JScript ^"%~dpnx0^"^ %site%') do set "javascript_output=!javascript_output!%%a"
echo !javascript_output!
::End Javascript function
::Start VBScript Code
:: Usage echo
:: Characters that need escaping brackets ()&
:: ^( ^) ^&
(
echo WScript.Echo "Hello world!"
echo WScript.Echo WScript.Arguments^(0^)
echo WScript.Echo "Unix Time Stamp: " ^& ^(DateDiff^("s", "01/01/1970 00:00:00", Now^(^)^)^)
echo WScript.Quit
)>>"%~n0-temp.vbs"
::End VBScript code
:: start VBScript Execution function args
for /f "tokens=*" %%a in ('cscript //nologo //E:VBScript ^"%~n0-temp.vbs^"^ %site%') do set "vbs_output=!vbs_output!%%a"
del %~n0-temp.vbs
echo !vbs_output!
:: End VBScript function
pause
exit /b
@end
//Start Javascript Code
/* easy */
// Instantiate the needed component to make url queries
var http = WScript.CreateObject('MSXML2.ServerXMLHTTP.6.0');
// Retrieve the url parameter
var url = WScript.Arguments.Item(0)
//Make the request
http.open("GET", url, false);
http.send();
//If we get a OK from server (status 200), output to console
if (http.status === 200) WScript.Echo(http.responseText);
//Close script
WScript.Quit(0);
//End Javascript code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment