【发布时间】:2021-09-09 19:02:08
【问题描述】:
如何确定 Windows 是使用 UEFI 启动的,还是使用 Python 启动的 BIOS?
【问题讨论】:
如何确定 Windows 是使用 UEFI 启动的,还是使用 Python 启动的 BIOS?
【问题讨论】:
根据this website,你可以这样做:
import subprocess
out = subprocess.check_output(['bcdedit']).decode('utf-8')
is_loader = False
for line in out.split('\n'):
# Ignore lines until the Windows Boot Loader section
if not is_loader and 'Windows Boot Loader' in line:
is_loader = True
if not is_loader:
continue
# Ignore lines until the path subsection
if not line.startswith('path'):
continue
# Receives 'EXE' (BIOS) or 'EFI' (UIEF)
boot_type = line[-3:].upper()
# You can also use an if-else expression
# Receives 'BIOS' or 'UIEF'
# boot_type = 'BIOS' if line[-3:] == 'exe' else 'UIEF'
import re
with open(r'C:\Windows\Panther\setupact.log') as f:
pattern = re.compile(r'Detected boot environment: (\w+)')
# Iterate over every line of file until finds a match
for line in f:
match = pattern.search(line)
if match:
# Receives 'BIOS' or 'UEFI'
boot_type = match.group(1).upper()
break
【讨论】: