C#.Net操作注册表RegistryKey

jopen 11年前

1、加键加值 

    string appName = "PowerOffOnTime";        //获取执行该方法的程序集,并获取该程序集的文件路径(由该文件路径可以得到程序集所在的目录)        string thisExecutablePath = System.Reflection.Assembly.GetExecutingAssembly().Location;        //SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run注册表中这个路径是开机自启动的路径        Microsoft.Win32.RegistryKey Rkey =            Microsoft.Win32.Registry.LocalMachine.CreateSubKey            ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");        Rkey.SetValue(appName, thisExecutablePath);         Rkey.Close();  

2、读得键值

    Microsoft.Win32.RegistryKey Rkey =                           Microsoft.Win32.Registry.LocalMachine.CreateSubKey                           ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");        string  Key = Rkey.GetValue("PowerOffOnTime").ToString();