欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#操作windows注册表的方法

程序员文章站 2022-04-11 08:20:49
本文实例讲述了c#操作windows注册表的方法。分享给大家供大家参考。具体如下: 此代码演示了如何读取和写入注册表 读取注册表: private strin...

本文实例讲述了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#程序设计有所帮助。