Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determine if Windows 8 secure boot is enabled

I'm writing a security application which validates many security rules and policies on user machines. I need to implement a test method that returns true when Windows 8's Secure Boot feature is enabled, or false when it disabled.

I searched for information and I saw that this is a BIOS feature. So my question is: is it possible to get the status of Windows 8 Secure Boot using C# code? If yes, how?

Secure Boot from BIOS


Update: See the answer of @magicandre1981, It's important to mention that the state registry key exists only when secure boot feature is supported. If you're not finding this key on your machine, probably your machine doesn't support secure boot.

to check secure boot status / support go to run - > msinfo32.exe and search for "Secure Boot State"

like image 790
Ofir Avatar asked Aug 11 '13 13:08

Ofir


Video Answer


2 Answers

MSinfo32.exe read the value UEFISecureBootEnabled from the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecureBoot\State.

enter image description here

On my system SecureBoot is disabled and return value is 0. So I assume that 1 means enabled.

like image 118
magicandre1981 Avatar answered Oct 17 '22 10:10

magicandre1981


Good code for Windows 10 too of course and should handle most conditions including legacy or missing key and exception, as well the future.. Prints to console whilst also returning the flag for batch or script use:

using System;
using Microsoft.Win32;

namespace CheckSecureBoot
{
    class Program
    {
        static int Main()
        {
            int rc = 0;
            string key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecureBoot\State";
            string subkey = @"UEFISecureBootEnabled";
            try
            {
                object value = Registry.GetValue(key, subkey, rc);
                if (value != null)
                    rc = (int)value;
            }
            catch { }
            Console.WriteLine($@"{subkey} is {(rc >= 1 ? "On" : "Off")} ({rc.ToString()})");
            return rc;
        }
    }
}
like image 2
mattjs Avatar answered Oct 17 '22 10:10

mattjs