12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Win32;
- namespace Aitex.UI.Charting.ViewModel
- {
- /// <summary>
- /// 注册表工具
- /// </summary>
- public class RegEdit
- {
- /// <summary>
- /// 注册表读取
- /// </summary>
- /// <param name="appName"></param>
- /// <param name="keyName"></param>
- /// <param name="keyValue"></param>
- /// <returns></returns>
- public static string ReadRegedit(string appName, string keyName)
- {
- if (string.IsNullOrEmpty(appName) || string.IsNullOrEmpty(keyName))
- return string.Empty;
- string ret = string.Empty;
- RegistryKey hklm = Registry.CurrentUser;
- RegistryKey software = hklm.OpenSubKey("Software", false);
- RegistryKey aimdir = software.OpenSubKey(appName);
- if (aimdir != null)
- {
- ret = Convert.ToString(aimdir.GetValue(keyName));
- aimdir.Close();
- }
- software.Close();
- hklm.Close();
- return ret;
- }
- /// <summary>
- /// 注册表修改
- /// </summary>
- /// <param name="appName"></param>
- /// <param name="keyName"></param>
- /// <param name="keyValue"></param>
- /// <returns></returns>
- public static bool WriteRegedit(string appName, string keyName, string keyValue)
- {
- if (string.IsNullOrEmpty(appName) || string.IsNullOrEmpty(keyName))
- return false;
- RegistryKey hklm = Registry.CurrentUser;
- RegistryKey software = hklm.OpenSubKey("Software", true);
- RegistryKey aimdir = software.CreateSubKey(appName);
- aimdir.SetValue(keyName, keyValue);
- aimdir.Close();
- software.Close();
- hklm.Close();
- return true;
- }
- }
- }
|