简体   繁体   中英

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?

从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"

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

在此输入图像描述

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

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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM