MasstransferExporter/MasstransferCommon/Utils/RegistryHelper.cs

32 lines
934 B
C#

namespace MasstransferCommon.Utils;
using Microsoft.Win32;
/// <summary>
/// 注册表工具类
/// </summary>
public static class RegistryHelper
{
public static void WriteValue(string keyPath, string valueName, object value, RegistryValueKind valueKind)
{
using var key = Registry.CurrentUser.CreateSubKey(keyPath);
key.SetValue(valueName, value, valueKind);
}
public static object? ReadValue(string keyPath, string valueName)
{
using var key = Registry.CurrentUser.OpenSubKey(keyPath);
return key?.GetValue(valueName);
}
public static void DeleteValue(string keyPath, string valueName)
{
using var key = Registry.CurrentUser.OpenSubKey(keyPath, writable: true);
key?.DeleteValue(valueName);
}
public static void DeleteKey(string keyPath)
{
Registry.CurrentUser.DeleteSubKeyTree(keyPath, throwOnMissingSubKey: false);
}
}