After rebuilding a HDD using ImageX and a WIM, the BCD sometimes gets corrupted. I therefor need to rebuid the BCD from a script running unattended in a command prompt.
The below code does the job, when entered manually. I need help to automate it (see further below code example):
bootrec.exe /fixmbr
bootsect.exe /nt60 all /force
attrib -h -s C:\boot\BCD
del C:\boot\BCD
bcdedit.exe /createstore c:\boot\bcd.temp
bcdedit.exe /store c:\boot\bcd.temp /create {bootmgr} /d "Windows Boot Manager"
bcdedit.exe /import c:\boot\bcd.temp
bcdedit.exe /set {bootmgr} device partition=C:
bcdedit.exe /timeout 10
attrib -h -s C:\boot\bcd.temp
del c:\boot\bcd.temp
bcdedit.exe /create /d "Microsoft Windows" /application osloader
bcdedit.exe /set {GUID} device partition=C:
bcdedit.exe /set {GUID} osdevice partition=C:
bcdedit.exe /set {GUID} path \Windows\system32\winload.exe
bcdedit.exe /set {GUID} systemroot \Windows
bcdedit.exe /displayorder {GUID}
As started above, I need to run this in a unattended command prompt. The output from the 6th last statement "bcdedit.exe /create /d "Microsoft Windows" /application osloader" is a newly creates GUID. This ID is needed in the following commands.
How do I load this new GUID from bcdedit to a variable I can call in the following code?
Best Regards Henrik V. Nielsen
If other should face the same problem, I solved it by adding the following line.
For /F "tokens=2 delims={}" %%i in ('bcdedit.exe') do (set _NEWGUID=%%i)
This works because there is only one GUID in the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With