C# 操作注冊表


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 == "";
        }

 

當然用注冊表還可以去記錄一些其他的許許多多的信息,具體看你的需求啦!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM