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?
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With