首页 > 编程 > C# > 正文

C#操作windows注册表的方法

2020-01-24 01:54:04
字体:
来源:转载
供稿:网友

本文实例讲述了C#操作windows注册表的方法。分享给大家供大家参考。具体如下:

此代码演示了如何读取和写入注册表

读取注册表:

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

写入注册表:

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

希望本文所述对大家的C#程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表