MasstransferExporter/MasstransferCommon/Utils/RegistryHelper.cs

32 lines
919 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, false);
}
public static void DeleteKey(string keyPath)
{
Registry.CurrentUser.DeleteSubKeyTree(keyPath, false);
}
}