此代码演示了如何读取和写入注册表
读取注册表
private string GetRegistShellData(string RegistName) { try { string registData, SubregistData; RegistryKey hkml = Registry.LocalMachine; RegistryKey software = hkml.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); registData = software.GetValue(RegistName).ToString(); SubregistData = registData.Substring(0, 2); return SubregistData; } catch (Exception excp) { MessageBox.Show("GetRegistShellData错误" + excp.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return ""; } /// <summary>
写入注册表
private void RenameRegistData() { try { string registData1; RegistryKey hkml = Registry.LocalMachine; RegistryKey software2 = hkml.OpenSubKey(@"SOFTWARE\"+ Shadowin + @"\SysToolSign", true); registData1 = software2.GetValue("Sign").ToString(); software2.SetValue("Sign", "1"); registData1 = software2.GetValue("Sign").ToString(); } catch (Exception excp) { MessageBox.Show("RenameRegistData错误" + excp.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return ; }