[英]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. 我需要实现一个测试方法,该方法在启用Windows 8的安全启动功能时返回true,或在禁用时返回false。
I searched for information and I saw that this is a BIOS feature. 我搜索了信息,我看到这是一个BIOS功能。 So my question is: is it possible to get the status of Windows 8 Secure Boot using C# code? 所以我的问题是:是否可以使用C#代码获取Windows 8安全启动的状态? 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. 更新:请参阅@ magicandre1981的答案,重要的是要提到状态注册表项仅在支持安全启动功能时存在。 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并搜索“安全启动状态”
MSinfo32.exe
read the value UEFISecureBootEnabled
from the registry under HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State
. MSinfo32.exe
从HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State
下的注册表中读取值UEFISecureBootEnabled
。
On my system SecureBoot
is disabled and return value is 0. So I assume that 1 means enabled. 在我的系统上, SecureBoot
被禁用,返回值为0.所以我假设1表示已启用。
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: 当然,Windows 10的代码也很好,并且应该处理大多数条件,包括遗留密钥和缺失密钥和异常,以及未来。打印到控制台同时还返回批处理或脚本使用的标志:
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.