首页 > 代码库 > 如何写入和读取注册表

如何写入和读取注册表

参考下面代码,写入和读取注册表

 1             string registrySubKey = @"SOFTWARE\RegistryTest"; 2             RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(registrySubKey, true); 3             if (registryKey == null)//没有则创建路径 4             { 5                 Registry.LocalMachine.CreateSubKey(registrySubKey); 6                 registryKey = Registry.LocalMachine.OpenSubKey(registrySubKey, true); 7             } 8             //写入注册表 9             registryKey.SetValue("Name", "zhangsan");10             //读出注册表11             Console.WriteLine(registryKey.GetValue("Name"));12 13             Console.Read();