C#中對注冊表的操作用類Registry.RegistryKey實現。
其中
1、創建注冊表:CreateSubKey , SetValue;
2、刪除注冊表:DeleteSubKey,DeleteSubKeyTree , DeleteValue
3、獲取注冊表:OpenSubKey , GetValue
用注冊表可以實現很多的需求:比如說記錄是不是第一次打開該軟件:
我們就可以用一個注冊表來實現;
public static bool IsFirstTimeLaunch()
{
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(Strings.RegBasePath);
string a = (string)registryKey.GetValue("FirstTimeLaunch", "");
if (a == "")
{
registryKey.SetValue("FirstTimeLaunch", DateTime.Now.ToString());
}
return a == "";
}
當然用注冊表還可以去記錄一些其他的許許多多的信息,具體看你的需求啦!