how to get firmware type of windows?

Gopika Lakshmi 85 Reputation points
2025-01-16T07:06:30.9433333+00:00

I tried the below method, but it seems vague.

if (EnablePrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE) != ERROR_SUCCESS) 
{ 
return 0; //(unknown)

}

BYTE buffer[1];

DWORD result = GetFirmwareEnvironmentVariableW(SECURE_BOOT, EFI_GUID, buffer, sizeof(buffer));

if (result == 0) {

    DWORD error = GetLastError();

    if (error == ERROR_INVALID_FUNCTION || error == ERROR_ENVVAR_NOT_FOUND)  
     return FirmwareType_Legacy;

    return FirmwareType_Legacy;

}

return FirmwareType_UEFI;  
```is there any better approach?
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,848 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 12,591 Reputation points Microsoft Vendor
    2025-01-16T07:36:52.71+00:00

    Hi,

    There is Win Api:

    GetFirmwareType function (winbase.h)

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.