You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过编程判断Windows Hello人脸识别是否启用?

判断Windows Hello人脸识别是否启用的C#实现方案

一、注册表方法(优先推荐)

你之前检查的注册表项不准确,以下是可用于判断的系统级和用户级注册表路径:

1. 系统级功能启用状态

检查设备是否全局开启人脸识别:

  • 注册表路径:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Biometrics\FaceOn\Configuration
  • 键值:Enabled(DWORD类型),值为1表示系统级启用,0表示禁用

2. 用户级注册状态

判断当前用户是否已注册人脸信息:

  • 注册表路径:HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\UserTile
  • 两种验证方式:
    • 检查是否存在以FaceLogon_开头的子项(对应已注册的人脸模板)
    • 检查LastLoggedOnProvider键值是否等于人脸凭据提供程序GUID:{8AF662BF-6D77-4238-A5FF-220733B108AE}

C#代码实现

using Microsoft.Win32;
using System.Linq;

public static class WindowsHelloChecker
{
    private const string FaceCredentialProviderGuid = "{8AF662BF-6D77-4238-A5FF-220733B108AE}";

    public static bool IsFaceRecognitionEnabled()
    {
        // 验证系统级人脸识别是否开启
        using (var localMachineKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Biometrics\FaceOn\Configuration"))
        {
            if (localMachineKey == null)
                return false;
            
            var enabledValue = localMachineKey.GetValue("Enabled");
            if (enabledValue is int enabled && enabled != 1)
                return false;
        }

        // 验证当前用户是否注册了人脸
        using (var currentUserKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\UserTile"))
        {
            if (currentUserKey == null)
                return false;
            
            // 方式1:检查FaceLogon_子项
            var subKeys = currentUserKey.GetSubKeyNames();
            if (subKeys.Any(k => k.StartsWith("FaceLogon_")))
                return true;
            
            // 方式2:检查凭据提供程序
            var lastProvider = currentUserKey.GetValue("LastLoggedOnProvider") as string;
            if (!string.IsNullOrEmpty(lastProvider) && lastProvider.Equals(FaceCredentialProviderGuid, StringComparison.OrdinalIgnoreCase))
                return true;
        }

        return false;
    }
}

二、备选方案:调用WinBio API

如果注册表方法在部分系统版本中存在兼容性问题,可以直接调用Windows生物识别API(WinBio)检测:

C#代码实现

using System;
using System.Runtime.InteropServices;

public static class WinBioFaceChecker
{
    private const int WINBIO_TYPE_FACE = 0x00000002;
    private const int WINBIO_SUCCESS = 0;

    [DllImport("winbio.dll", CharSet = CharSet.Unicode)]
    private static extern int WinBioEnumBiometricUnits(int biometricType, out IntPtr unitArray, out uint unitCount);

    [DllImport("winbio.dll")]
    private static extern int WinBioFree(IntPtr buffer);

    [StructLayout(LayoutKind.Sequential)]
    private struct WINBIO_UNIT_IDENTITY
    {
        public uint UnitId;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DeviceInstanceId;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string Description;
    }

    public static bool IsFaceRecognitionRegistered()
    {
        IntPtr unitArray = IntPtr.Zero;
        uint unitCount = 0;

        try
        {
            int result = WinBioEnumBiometricUnits(WINBIO_TYPE_FACE, out unitArray, out unitCount);
            if (result != WINBIO_SUCCESS || unitCount == 0)
                return false;

            // 可进一步调用WinBioEnumEnrollments确认当前用户是否有注册模板
            return true;
        }
        finally
        {
            if (unitArray != IntPtr.Zero)
                WinBioFree(unitArray);
        }
    }
}

注意事项

  • 读取HKEY_LOCAL_MACHINE下的注册表项可能需要管理员权限
  • 不同Windows版本的注册表路径可能略有差异,建议在目标系统上验证
  • WinBio方法需要应用以Windows 10及以上版本为目标平台,部分场景可能需要声明生物识别权限

内容的提问来源于stack exchange,提问作者Kiralyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 20:42:15