【问题标题】:Find out if system (Windows) was booted with BIOS or UEFI with Python 3查明系统 (Windows) 是使用 BIOS 启动还是使用 Python 3 启动 UEFI
【发布时间】:2021-09-09 19:02:08
【问题描述】:

如何确定 Windows 是使用 UEFI 启动的,还是使用 Python 启动的 BIOS?

【问题讨论】:

    标签: python windows bios uefi


    【解决方案1】:

    根据this website,你可以这样做:

    • 备选方案 1: 读取命令输出
    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'
    
    • 备选方案 2:读取日志文件
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-23
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2018-03-01
      • 1970-01-01
      • 2016-08-04
      相关资源
      最近更新 更多