batch.scripts
batch.scripts copied to clipboard
Suggestion for better and faster .net batch prologue
There is some suggestions to improvement on .net batch prologue. (as a source screenCapture.bat was used)
- If screenCapture.exe already exist, better to call immediately, skipping search for csc.exe
- screenCapture.bat produces screenCapture.exe at the place where it called, not where screenCapture.bat is located. if called from multiple laces produces many screenCapture.exe
- if you call it from "another.bat" file located in the same folder using "sibling" pattern "call %0..\screenCapture", it will not compile (as ".bat" extension may not be added to "%0" inside screenCapture.bat under Win7)
Here is updated prologue I use:
// 2>nul||@goto :batch
/*
:batch
@echo off
if exist "%~dpn0.exe" (
"%~dpn0.exe" %*
exit /b %errorlevel%
)
setlocal
:: find csc.exe
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do set "csc=%%#"
if not exist "%csc%" (
echo no .net framework installed
exit /b 10
)
call %csc% /nologo /r:"Microsoft.VisualBasic.dll" /out:"%~dpn0.exe" "%~dpn0.bat" || (
exit /b %errorlevel%
)
"%~dpn0.exe" %*
endlocal & exit /b %errorlevel%
*/