32 lines
938 B
C#
32 lines
938 B
C#
|
using Microsoft.Win32;
|
|||
|
|
|||
|
namespace DispenserCommon.Utils;
|
|||
|
|
|||
|
/// <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, throwOnMissingSubKey: false);
|
|||
|
}
|
|||
|
}
|