C#操作windows注册表的方法
本文实例讲述了C#操作windows注册表的方法。分享给大家供大家参考。具体如下:
此代码演示了如何读取和写入注册表
读取注册表:
privatestringGetRegistShellData(stringRegistName) { try { stringregistData,SubregistData; RegistryKeyhkml=Registry.LocalMachine; RegistryKeysoftware=hkml.OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon",true); registData=software.GetValue(RegistName).ToString(); SubregistData=registData.Substring(0,2); returnSubregistData; } catch(Exceptionexcp) { MessageBox.Show("GetRegistShellData错误"+excp.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Warning); } return""; }
写入注册表:
privatevoidRenameRegistData() { try { stringregistData1; RegistryKeyhkml=Registry.LocalMachine; RegistryKeysoftware2=hkml.OpenSubKey(@"SOFTWARE\"+Shadowin+@"\SysToolSign",true); registData1=software2.GetValue("Sign").ToString(); software2.SetValue("Sign","1"); registData1=software2.GetValue("Sign").ToString(); } catch(Exceptionexcp) { MessageBox.Show("RenameRegistData错误"+excp.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Warning); } return; }
希望本文所述对大家的C#程序设计有所帮助。