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

 

当然用注册表还可以去记录一些其他的许许多多的信息,具体看你的需求啦!

 

posted on 2016-11-02 09:50  shaozhuyong  阅读(2258)  评论(0编辑  收藏  举报