@echo off
Title AutoRun
rem
rem AutoRun (Startup Group for BartPE & Nu2Menu)
rem Copyright (c) 2003-2004 Erwin Veermans (http://www.veder.com/nwdskpe/)
rem

rem Skip AutoRun alltogether if Tag-file present on ramdrive
rem User may create this file by one of the AutoRuns to prevent a ReRun of AutoRun
if "%AutoRun%"=="1" goto _end
if exist %ramdrv%\autorun.tag goto _end

if not exist %SystemRoot%\System32\Keydown.exe goto _default
rem Disable all AutoRun by Toggling Scroll-Lock and Num-Lock and Caps-Lock ON
%SystemRoot%\System32\Keydown.exe 145 144 20
if errorlevel 1 goto _end
rem Confirm each AutoRun by toggling Scroll-Lock ON (Debug Mode)
%SystemRoot%\System32\Keydown.exe 145
if errorlevel 1 goto _debug
goto _default

:_debug
if not exist %SystemRoot%\System32\debugrun.cmd goto _end
start "Scroll-Lock detected: Entering Debug Mode" "%SystemRoot%\System32\debugrun.cmd"
goto _end

:_default
rem Pre-Default Group  
for %%i in (%SystemRoot%\System32\autorun1*.cmd %SystemRoot%\System32\autorun2*.cmd) do start "%%i" /wait /min "%%i"
for %%i in (%SystemRoot%\System32\autorun3*.cmd %SystemRoot%\System32\autorun4*.cmd) do start "%%i" /wait /min "%%i"
rem Default Group
for %%i in (%SystemRoot%\System32\autorun5*.cmd %SystemRoot%\System32\autorun_*.cmd) do start "%%i" /wait /min "%%i"
rem Post-Default Group
for %%i in (%SystemRoot%\System32\autorun6*.cmd %SystemRoot%\System32\autorun7*.cmd) do start "%%i" /wait /min "%%i"
for %%i in (%SystemRoot%\System32\autorun8*.cmd %SystemRoot%\System32\autorun9*.cmd) do start "%%i" /wait /min "%%i"
rem Post Default Concurrent Group (no /wait)
for %%i in (%SystemRoot%\System32\autorun0*.cmd) do start "%%i" /min "%%i"
:_end
