简体   繁体   English

以编程方式确定是否启用了Windows 8安全启动

[英]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? 如果有,怎么样?

从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. 更新:请参阅@ 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.exeHKEY_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.

相关问题 在Windows中以编程方式确定电源使用情况? - Determine power usage programmatically in Windows? 如何以编程方式确定是否为SharePoint 2010 Web应用程序启用了匿名访问? - How to programmatically determine if anonymous access is enabled for a SharePoint 2010 Web Application? 如何以编程方式确定Windows任务栏是否隐藏? - How can I determine programmatically whether the Windows taskbar is hidden or not? 以编程方式确定在Windows上上次修改文件的用户? - Programmatically determine user who last modified file on Windows? Windows 快速启动 - 如何确定上次启动/重新启动的时间 - Windows Fast Startup - How to determine when the last boot/reboot occured 确定ELMAH是否已启用? - Determine whether or not ELMAH is enabled? 以C#编程方式使用C#冷启动Windows Mobile 6.5设备 - Cold Boot Windows Mobile 6.5 Device Programmatically Using C# 如何以编程方式检测Windows桌面应用程序中是否启用了javascript? (WebBrowser控件) - How can you programmatically detect if javascript is enabled/disabled in a Windows Desktop Application? (WebBrowser Control) 如何在启用Windows身份验证的情况下以编程方式启动和停止ASP.NET Core 2.1应用程序? - How to start and stop an ASP.NET Core 2.1 app programmatically with Windows Authentication enabled? 如何在 C# 中以编程方式读取 Windows NTFS $Secure 文件(和/或 $SDS 流) - How do I read the Windows NTFS $Secure file (and/or the $SDS stream) programmatically in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM