上面是读取函数,下面是写入函数,自己慢慢看看吧。
private void GetSettings()
{
Microsoft.Win32.RegistryKey Reg;
Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", true);
Reg.CreateSubKey("MMsg");
Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\MMsg", true);
this.comServer.Text = Reg.GetValue("ServerName", System.Configuration.ConfigurationSettings.AppSettings["ServerIP"].ToString()).ToString();
this.comUser.Text = Reg.GetValue("LoginName", "").ToString();
this.checkPass.Checked = Convert.ToBoolean(Reg.GetValue("SavePassword", false));
if (this.checkPass.Checked)
{
this.txtPassword.Text = Reg.GetValue("Password", "").ToString();
}
this.checkStart.Checked = Convert.ToBoolean(Reg.GetValue("AutoStart", false));
this.checkLogin.Checked = Convert.ToBoolean(Reg.GetValue("AuorLogin", false));
}
private void SaveSettings()
{
Microsoft.Win32.RegistryKey Reg;
Reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\MMsg", true);
Reg.SetValue("ServerName", ServerIP);
Reg.SetValue("LoginName", selfInfo.UserID);
Reg.SetValue("Password",selfInfo.UserPassword);
Reg.SetValue("AutoStart", AutoStart);
Reg.SetValue("AuorLogin",AutoLogin);
Reg.SetValue("SavePassword",SavePassword);
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (AutoStart)//开机自动启动
{
Reg.SetValue("MMsg", Application.ExecutablePath);
}
else
{
string m = Reg.GetValue("MMsg", "").ToString();
if ( m != "")
Reg.DeleteValue("MMsg");
}
}
温馨提示:内容为网友见解,仅供参考