問題1spa
在對註冊表進行操做時沒法生成註冊表相關的類code
解決辦法:blog
增長頭文件using Microsft.Win32;string
問題2it
在運行程序時報錯同時註冊表沒有新的信息生成class
解決辦法:foreach
以管理員身份運行程序程序
如下是對註冊表信息的一些操做: im
private string GetRegistData(string name)
{ string registData; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("Software", true); RegistryKey aimdir = software.OpenSubKey("NewTimeyear", true); registData = aimdir.GetValue(name).ToString(); return registData; } private void WTRegedit(string name, string tovalue) { RegistryKey hklm = Registry.CurrentUser; RegistryKey software = hklm.OpenSubKey("Software", true); RegistryKey aimdir = software.CreateSubKey("NewTimeyear"); aimdir.SetValue(name, tovalue); } private bool IsRegeditExit(string name) { bool _exit = false; string[] subkeyNames; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("Software", true); RegistryKey aimdir = software.OpenSubKey("NewTimeyear", true); if (aimdir == null) { return false; } subkeyNames = aimdir.GetSubKeyNames(); foreach (string keyName in subkeyNames) { if (keyName == name) { _exit = true; return _exit; } } return _exit; }