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