Search code examples
windowsuefi

Are there any ways to get UEFI boot items on Windows


I've been working on UEFI and GPT recently. I want to get the UEFI boot item under WIndows, but I looked at MSDN and found no suitable API. Please ask me how to query the UEFI boot item under Windows

It just likes this below:

1


Solution

  • You can use the GetFirmwareEnvironmentVariableA function to get the BootOrder variable first and then the single boot options (Boot####).

    You need the SE_SYSTEM_ENVIRONMENT_NAME privilege to call GetFirmwareEnvironmentVariableA.

    The structures and names of the required variables are defined in the uefi specification, starting at chapter 3.

    DWORD BootOrderContentLength;
    DWORD Error;
    BYTE BootOrderContent[256];
    
    BootOrderContentLength = GetFirmwareEnvironmentVariableA(
        "BootOrder",
        "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}",
        (VOID*)BootOrderContent,
        (DWORD)sizeof(BootOrderContent));
    
    if (BootOrderContentLength == 0) {
        Error = GetLastError();
        //...
    }