I've made some small improvements:
- searching on boot device is off by default; if you use /sbd as parameter it will also search on boot device;
- if /ab parameter is used, it will automatically boot into Windows if only one bootable partition is found.
The script:
!BAT
setlocal
clear
echo Please wait, searching...
set SKIPPED=0
set N=0
set TMSZ=0
set BDN=-1
if "%?_BOOT:~1,2%"=="hd" set BDN=%?_BOOT:~3,1%
set DETTYPE=ver
set AB=0
:loopb
if "%1"=="" goto :endloopb
######### if the batch file was started with /sbd as parameter it will also search
######### on the boot device (if it's seen as a HDD). Usually is the USB drive (hd0)
if "%1"=="/sbd" set BDN=-1
######### if the batch file was started with /fd as parameter it will use
######### a faster OS type detection but with slightly less accuracy
if "%1"=="/fd" set DETTYPE=len
######### if the batch file was started with /ab as parameter
######### it will automatically boot Windows if only one is found
if "%1"=="/ab" set AB=1
shift
goto :loopb
:endloopb
debug on > nul
find --devices=h > (md)0x220+8
:loop
cat --skip=%SKIPPED% --number=1 --locate=" (hd" (md)0x220+8 | set PPOSB=
if "%PPOSB%"=="" goto endloop
set /a SKIPPED=0x%PPOSB%+7 > nul
cat --skip=%SKIPPED% --number=1 --locate=")" (md)0x220+8 | set PPOSE=
if "%PPOSE%"=="" goto endloop
set /a PPOSL=0x%PPOSE%-0x%PPOSB% > nul
set /a SKIPPED=0x%PPOSB%+1 > nul
cat --skip=%SKIPPED% --length=%PPOSL% --locate=" " (md)0x220+8 && set /a SKIPPED=0x%PPOSB%+7 > nul && goto :loop
cat --skip=%SKIPPED% --length=%PPOSL% --locate="," --number=1 (md)0x220+8 | set CPOS=
if "%CPOS%"=="" set /a SKIPPED=0x%PPOSB%+7 > nul && goto :loop
set /a PNL=0x%PPOSE%-0x%CPOS%-1 > nul
set /a SKIPPED=0x%CPOS%+1 > nul
cat --skip=%SKIPPED% --length=%PNL% (md)0x220+8 | set PN=
set /a HDNL=0x%CPOS%-0x%PPOSB%-4 > nul
set /a SKIPPED=0x%PPOSB%+4 > nul
cat --skip=%SKIPPED% --length=%HDNL% (md)0x220+8 | set HDN=
if %PN%>=4 goto :notgood
if %BDN%==%HDN% goto :notgood
checkrange 0x06:0x0e parttype (hd%HDN%,%PN%) > nul || goto :notgood
ls (hd%HDN%,%PN%)/ > (md)0x300+8
cat --locate=\0 --number=1 (md)0x300+8 | set ENDFILE=
set /a ENDFILE=0x%ENDFILE% > nul
if not "%ENDFILE%"=="0" write --offset=%ENDFILE% (md)0x300+8 \ \0 > nul
cat --locate=" ntldr " --number=1 (md)0x300+8 > nul || goto :nont
cat --length=0 (hd%HDN%,%PN%)/ntldr | set NTS=
set /a NTS=0x%NTS:~14% > nul
if %NTS%<=76799 goto :nont
if %NTS%>=1048577 goto :nont
set /a N=%N%+1 > nul
set CLCMD=chainloader
if "%DETTYPE%"=="ver" goto :ntver
:ntlen
if %NTS%>=268976 set OS=\ XP\ 64-bit\ or\ Server\ 2003 && goto :esnt
if %NTS%>=218976 set OS=\ XP && goto :esnt
if %NTS%>=185208 set OS=\ 2000 && goto :esnt
set OS=\ NT
set CLCMD=chainloader --force --load-segment=0x2000
goto :esnt
:ntver
set majver=0
set minver=0
map --mem=0x11000 (hd%HDN%,%PN%)/ntldr (rd) > nul || goto :ntlen
cat --hex --number=1 --locate=\x01\x00\x46\x00\x69\x00\x6C\x00\x65\x00\x56\x00 (rd)+1 > nul
set /a offbase = %?% + 28 > nul
if "%offbase%"=="29" goto :ntlen
cat --hex --length=5 --skip=%offbase% (rd)+1 | set line=
set majver=%line:~-5,1%
set minver=%line:~-1,1%
set OS=
if %majver%<=4 set OS=\ NT && set CLCMD=chainloader\ --force\ --load-segment=0x2000 && goto :esnt
if "%majver%%%minver%"=="50" set OS=\ 2000 && goto :esnt
if "%majver%%%minver%"=="51" set OS=\ XP && goto :esnt
if "%majver%%%minver%"=="52" set OS=\ XP 64-bit or Server 2003
:esnt
if %HDN%==0 set HDNT=first && set HDNTR=USB drive
if %HDN%==1 set HDNT=second && set HDNTR=first internal HDD
if %HDN%==2 set HDNT=third && set HDNTR=second internal HDD
if %HDN%==3 set HDNT=fourth && set HDNTR=third internal HDD
if %HDN%>=4 set HDNT=%HDN%th && set /a HDNN=%HDN%+1 > nul && set HDNTR=%HDN%th internal HDD
if %HDN%==0 set REMAP=
if %HDN%==0 set AFTERR=
if %HDN%>=1 set REMAP=\r\nmap (hd%HDN%) (hd0)\r\nmap (hd0) (hd%HDN%)\r\nmap --rehook
if %HDN%>=1 set AFTERR=\ \&\& boot\r\nmap (hd%HDN%) (hd0)\r\nmap (hd0) (hd%HDN%)\r\nmap --rehook\r\nroot (bd) \> nul\r\n%CLCMD% (hd%HDN%,%PN%)/ntldr
if %PN%==0 set PNT=first
if %PN%==1 set PNT=second
if %PN%==2 set PNT=third
if %PN%==3 set PNT=fourth
set STATUS=
set HIDST=
hiddenflag (hd%HDN%,%PN%) > nul && set HIDST=\ (hidden) && set UNHCOM=\r\nunhide (hd%HDN%,%PN%) \> nul
set BWINM%N%=title Boot to Windows%OS% on %HDNT% HDD, %PNT% partition%HIDST%\\nUsually the %HDNTR%... %UNHCOM%%%REMAP%\r\nroot (hd0,%PN%) \> nul\r\%CLCMD% /ntldr%AFTERR%\r\n
call call Fn.12 "%^BWINM%N%%%"
set /a TMSZ=%TMSZ%+%@retval% > nul
:nont
cat --locate=" bootmgr " --number=1 (md)0x300+8 > nul || goto :nomgr
cat --length=0 (hd%HDN%,%PN%)/bootmgr | set MGRS=
set /a MGRS=0x%MGRS:~14% > nul
if %MGRS%<=204799 goto :nomgr
if %MGRS%>=1572865 goto :nomgr
if "%DETTYPE%"=="ver" goto :mgrver
if %MGRS%==438840 set OS=\ Vista && goto :esmgr
:mgrlen
if %MGRS%>=390971 set OS=\ 8, 8.1 or Server 2012 && goto :esmgr
if %MGRS%>=358410 set OS=\ 7 or Server 2008 && goto :esmgr
set OS=\ Vista or Server 2008
:mgrver
set majver=0
set minver=0
map --mem=0x11000 (hd%HDN%,%PN%)/bootmgr (rd) > nul || goto :mgrlen
cat --hex --number=1 --locate=\x01\x00\x46\x00\x69\x00\x6C\x00\x65\x00\x56\x00 (rd)+1 > nul
set /a offbase = %?% + 28 > nul
if "%offbase%"=="29" goto :mgrlen
cat --hex --length=5 --skip=%offbase% (rd)+1 | set line=
set majver=%line:~-5,1%
set minver=%line:~-1,1%
set OS=
if "%majver%%%minver%"=="60" set OS=\ Vista or Server 2008 && goto :esmgr
if "%majver%%%minver%"=="61" set OS=\ 7 or Server 2008 R2 && goto :esmgr
if "%majver%%%minver%"=="62" set OS=\ 8 or Server 2012
if "%majver%%%minver%"=="63" set OS=\ 8.1
:esmgr
set /a N=%N%+1 > nul
if %HDN%==0 set HDNT=first && set HDNTR=USB drive
if %HDN%==1 set HDNT=second && set HDNTR=first internal HDD
if %HDN%==2 set HDNT=third && set HDNTR=second internal HDD
if %HDN%==3 set HDNT=fourth && set HDNTR=third internal HDD
if %HDN%>=4 set HDNT=%HDN%th && set /a HDNN=%HDN%+1 > nul && set HDNTR=%HDN%th internal HDD
if %HDN%==0 set REMAP=
if %HDN%==0 set AFTERR=
if %HDN%>=1 set REMAP=\r\nmap (hd%HDN%) (hd0)\r\nmap (hd0) (hd%HDN%)\r\nmap --rehook
if %HDN%>=1 set AFTERR=\ \&\& boot\r\nmap (hd%HDN%) (hd0)\r\nmap (hd0) (hd%HDN%)\r\nmap --rehook\r\nroot (bd) \> nul\r\nchainloader (hd%HDN%,%PN%)/bootmgr
if %PN%==0 set PNT=first
if %PN%==1 set PNT=second
if %PN%==2 set PNT=third
if %PN%==3 set PNT=fourth
set HIDST=
set UNHCOM=
hiddenflag (hd%HDN%,%PN%) > nul && set HIDST=\ (hidden) && set UNHCOM=\r\nunhide (hd%HDN%,%PN%) \> nul
set BWINM%N%=title Boot to Windows%OS% on %HDNT% HDD, %PNT% partition%HIDST%\\nUsually the %HDNTR%...%UNHCOM%%%REMAP%\r\nroot (hd0,%PN%) \> nul\r\nchainloader /bootmgr%AFTERR%\r\n
call call Fn.12 "%^BWINM%N%%%"
set /a TMSZ=%TMSZ%+%@retval% > nul
:nomgr
:notgood
set /a SKIPPED=0x%PPOSE%+2 > nul
goto :loop
:endloop
if not %N%==0 goto :not0
endlocal
clear
echo No bootable Windows NT/2000/XP/Vista/7/8/8.1 partitions found, returning to main menu...
pause --wait=5 || goto :finish
goto :finish
:not0
clear
set I=0
set OFFSET=0
if "%N%"=="1" if "%AB%"=="1" set OFFSET=13 && set /a TMSZ=%TMSZ%+13 > nul
call Fn.12 "\r\ntitle\r\nroot\r\ntitle Return to main menu...\r\nconfigfile /menu.lst\r\n\0"
set /a MBSZ=%TMSZ%+%@retval%/512+1 > nul
if "%N%"=="1" if "%AB%"=="1" write (md)0x300+%MBSZ% timeout 0\r\n\r\n > nul
set /a N=%N%+1 > nul
:wloop
set /a I=%I%+1 > nul
if %I%>=%N% goto :endwloop
call write --offset=%OFFSET% (md)0x300+%MBSZ% %^BWINM%I%%% > nul
call call Fn.12 "%^BWINM%I%%%"
set /a OFFSET=%OFFSET%+%@retval% > nul
goto :wloop
:endwloop
write --offset=%OFFSET% (md)0x300+%MBSZ% \r\ntitle\r\nroot\r\ntitle Return to main menu...\r\nconfigfile /menu.lst\r\n\0 > nul
endlocal && set MBSZ=%MBSZ%
configfile (md)0x300+%MBSZ%
:finish
findbwin.g4b.gz 2.03KB
504 downloads
LE 3 dec 2014: updates the script to detect Windows 8.1 also.