2024-06-03 08:35:49 +00:00
|
|
|
|
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);
|
2024-09-05 11:56:27 +00:00
|
|
|
|
key?.DeleteValue(valueName, false);
|
2024-06-03 08:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DeleteKey(string keyPath)
|
|
|
|
|
{
|
2024-09-05 11:56:27 +00:00
|
|
|
|
Registry.CurrentUser.DeleteSubKeyTree(keyPath, false);
|
2024-06-03 08:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|