From d8697c7ddb2f5a804ca377cdde6f634a9b1d442c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Sat, 18 Jul 2026 00:01:14 +0800 Subject: [PATCH] * --- Shared/Utils/RegistryUtils.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Shared/Utils/RegistryUtils.cs b/Shared/Utils/RegistryUtils.cs index 3df0ca1..33b84e7 100644 --- a/Shared/Utils/RegistryUtils.cs +++ b/Shared/Utils/RegistryUtils.cs @@ -18,12 +18,17 @@ public static class RegistryUtils { return (result is string str && str == NULL_STRING ? null : result, true); } /// - /// 读取注册表键,若该键不存在则返回 。 + /// 读取注册表键,若该键不存在或发生异常则返回 。 /// 若键值为 ,则返回 null。 /// - public static object? ReadOrDefault(string keyPath, object? defaultValue) { - var (result, exists) = Read(keyPath); - return exists ? result : defaultValue; + public static object? TryRead(string keyPath, object? defaultValue = null) { + try { + var (result, exists) = Read(keyPath); + return exists ? result : defaultValue; + } catch (Exception ex) { + Logger.Warn(ex, $"读取注册表键失败({keyPath})"); + return defaultValue; + } } ///