Thursday, January 24, 2008

script for automating bcdedit

Windows Vista is using bcdedit in place of boot.ini of XP for boot loading. Though bcd is a better boot loader than XP, editing the boot data quite a few routine steps (which could have been easily automated in one command). Though easybcd does a good job in automating this, with a nice GUI, it has problems identifying partitions on my machine. I have quite a few partitions on my machine with Linux on it (actually its problem with bootpart, which easybcd uses to identify a partition & to extract the boot partition of the partition). If we can get the boot sector extracted from other OS, the editing part can be automated with the following script:

REM Script to create boot entries for PBR in Vista BCD
REM Usage: scr_name <"Description">
REM
REM Cleanup of bcd GUID: bcdedit /delete
REM Listing of BCD GUID: bcdedit /enum ALL [/v]

setlocal

set FILNAME=%1
set DESC=%2

set PBRDIR=\bcd

for /F "tokens=3 delims= " %%i in ('bcdedit /create /d %DESC% /application BOOTSECTOR') do set NEWGUID=%%i

bcdedit /set %NEWGUID% device boot

bcdedit /set %NEWGUID% PATH %PBRDIR%\%FILNAME%

bcdedit /displayorder %NEWGUID% /addlast

echo %NEWGUID% for %DESC% created


I had been planning to do this for quite sometime, but was not sure as to how do I store the GID generated by the first bcdedit command & pass it on to subsequent commands. I saw it on a
forum which gave me this idea. This is just an enhancement of that.

No comments: