c# 读写注册表
private void button2_Click(object sender, EventArgs e)
{
try
{
RegistryKey key = Registry.LocalMachine;
RegistryKey software = key.OpenSubKey("SOFTWARE\\Microsoft\\Office\\Excel\\Addins\\SGSOGC.ExcelAddIn", true);
var tem = software.GetValue("CurrenntUserInfo").ToString();
software.Close();
MessageBox.Show(tem);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
RegistryKey key = Registry.LocalMachine;
RegistryKey software = key.OpenSubKey("SOFTWARE\\Microsoft\\Office\\Excel\\Addins\\SGSOGC.ExcelAddIn", true); //该项必须已存在
software.SetValue("CurrenntUserInfo", textBox1.Text);
//在HKEY_LOCAL_MACHINE\SOFTWARE\test下创建一个名为“test”,值为“博客园”的键值。如果该键值原本已经存在,则会修改替换原来的键值,如果不存在则是创建该键值。
// 注意:SetValue()还有第三个参数,主要是用于设置键值的类型,如:字符串,二进制,Dword等等~~默认是字符串。如:
// software.SetValue("test", "0", RegistryValueKind.DWord); //二进制信息
key.Close();
}