‘写入注册表
private void Button3_Click(object sender, System.EventArgs e)
{
try
{
Microsoft.Win32.RegistryKey res ;
res = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test2",true);
//res =Microsoft.Win32.Registry.
if (res == null)
{
try
{
res = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\test2");
}
catch (Exception ee)
{
this.exeInfo.Text = ee.Message.ToString();
}
}
res.SetValue("test",this.txtWrite.Text );
this.exeInfo.Text = "pass!";
}
catch(Exception es)
{
this.exeInfo.Text = es.Message.ToString();
}
}
{
try
{
Microsoft.Win32.RegistryKey res ;
res = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test2",true);
//res =Microsoft.Win32.Registry.
if (res == null)
{
try
{
res = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\test2");
}
catch (Exception ee)
{
this.exeInfo.Text = ee.Message.ToString();
}
}
res.SetValue("test",this.txtWrite.Text );
this.exeInfo.Text = "pass!";
}
catch(Exception es)
{
this.exeInfo.Text = es.Message.ToString();
}
}
’读取注册表
private void Button4_Click(object sender, System.EventArgs e)
{
try
{
Microsoft.Win32.RegistryKey res;
res = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test2",true);
this.txtRead.Text= res.GetValue("test").ToString() ;
}
catch(Exception ee)
{
this.exeInfo.Text = ee.Message.ToString();
}
}
{
try
{
Microsoft.Win32.RegistryKey res;
res = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test2",true);
this.txtRead.Text= res.GetValue("test").ToString() ;
}
catch(Exception ee)
{
this.exeInfo.Text = ee.Message.ToString();
}
}