none
How to get/set BIOS variables? RRS feed

  • Question

  • Hi team,

    I wonder if we can get/set the value of the BIOS variables? I believe the answer is yes, so my question is how can we do it? Can we implement it using C#? Or must using C++?

    From my research, using UEFI interface seems to be a good way to do it, but I do not know how to achieve it, can you provide some demo or documentation? thanks for any help for this request.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 15, 2019 10:13 AM

Answers

All replies

  • Hello, 

    I would say that the best option can be to ask BIOS manufacturer to provide "BIOS Variables API SDK". 

    But question looks strange - if you working in Ring 0 drivers - you will have access to memory with this variables and should know where and which variable available. Other way - you would not have access to this and need to use what system provide.


    Sincerely, Highly skilled coding monkey.

    Monday, July 15, 2019 11:07 AM
  • In order to get some characteristics, you can also use Windows Management Instrumentation (WMI). An example in C#:

    using( var mc = new ManagementClass( "Win32_BIOS" ) )
    {
        using( var instances = mc.GetInstances( ) )
        {
            foreach( var instance in instances )
            {
                string manufacturer = instance.Properties["Manufacturer"]?.Value?.ToString( );
                string version = instance.Properties["Version"]?.Value?.ToString( );
                bool is_plug_and_play_supported = ( instance.Properties["BiosCharacteristics"].Value as UInt16[] )?.Any( c => c == 9 ) == true;
    
                Console.WriteLine( manufacturer );
                Console.WriteLine( version );
                Console.WriteLine( is_plug_and_play_supported );
            }
        }
    }
    


    Monday, July 15, 2019 11:38 AM
  • The phrase "BIOS variables" doesn't have any well-defined meaning.  BIOSes, as a rule, have been very poorly standardized over the years.  What, exactly, do you want to manipulate?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, July 16, 2019 12:56 AM
  • Hi Andrey & Tim,

    In fact, I want to read/set some BIOS/UEFI menu settings, just for example, I want to change the "secure boot control" from "Enabled" to "Disabled":

    @Viorel,

    Thanks for your advice, I believe WMI would be a good solution, but... I need to use UEFI to do it, now I have UEFI variables like GUID/Name/Attribute/...

    Do you have any idea? Thanks.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 16, 2019 1:59 AM
  • There is no way to change that value on the fly, and even if you could do so, it would be unethical.  That setting belongs to the user, and in many companies that setting is mandated by the IT department for security purposes.  Don't screw with it.

    I assume you are trying to do that so you don't have to have a driver signed by Microsoft, but believe me: it's way easier to get attestation signing then to try to hack around the requirement.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, July 16, 2019 5:58 AM
  • Hi Tim,

    I found there is a windows api can achieve my purpose, that is GetFirmwareEnvironmentVariableExW function, but how can I use it with C#? How to pass the parameters?

    Thanks,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 16, 2019 8:22 AM
  • > how can I use it with C#? How to pass the parameters?

    http://jasonprogramer.blogspot.com/2017/11/csetget-firmware-environment-variable.html


    Sincerely, Highly skilled coding monkey.

    • Marked as answer by Stanly Fan Wednesday, July 17, 2019 1:54 AM
    Tuesday, July 16, 2019 10:10 AM