1

Hi everyone,

I'm trying to make a WinPE iso and test if it has booted up on BIOS or UEFI mode. Currently I can test this with the following command:

reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType

This command returns 0x1 if the PC is booted into BIOS mode, or 0x2 if the PC is booted in UEFI mode.

Technet shows a script to show this automatically after WinPE has booted by adding this to startnet.cmd:

wpeutil UpdateBootInfo
for /f "tokens=2* delims=  " %%A in ('reg query HKLM\System \CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
:: Note: delims is a TAB followed by a space.
if %Firmware%==0x1 echo The PC is booted in BIOS mode.
if %Firmware%==0x2 echo The PC is booted in UEFI mode.

But when I boot up the WinPE, the cmd shows this error:

X:windows\system32>wpeinit UpdateBootInfo

X:\windows\system32>for /F "tokens=2* delims= " %A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%B 
echo was unexpected at this time.
X:\windows\system32>if ==0x1 echo The PC is booted in BIOS mode.
X:\windows\system32>_

Can anybody help me?

Thank you very much!

2
  • I think it is related to how the ifs are being evaluated: if %Firmware%==0x1, but I'm not sure.
    – elgato
    Oct 21 '15 at 13:15
  • Your for command is failing so Firmware is not being set.
    – DavidPostill
    Nov 2 '15 at 15:20
1

I was able to fix the script by replacing the whitespace in your delims variable and putting an actual tab and space in its place.

wpeutil UpdateBootInfo
for /f "tokens=2* delims=    " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B

if %Firmware%==0x1 echo The PC is booted in BIOS mode.
if %Firmware%==0x2 echo The PC is booted in UEFI mode.

**NOTE: ** I edited the script in notepad.exe to ensure proper encoding. A copy/paste of the above code may not work.

-1

Had the same issue because I was literally copying/pasting the text. Unfortunately there are (2) spaces after "delims" in the Technet example. Change the first space to be a tab and this should correct it. There's even the note mentioning it; it's been a long day. Be sure NOT to include the greater/less than signs below "<" and ">".

for /f "tokens=2* delims=" %%A....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.