用C#修改注册表,增添用户信息和删除用户信息。

以下是接口代码,添加用户的时候需要将用户信息写入注册表,删除z用户的时候需要将用户信息在注册表中删除,并且需要在注册表中写入手续费factorage的信息。
用c#编写。

interface Isystem
{
private userStruct[] users;
private float factorage;
public float Factorage
{
get { return factorage; }
set { this.factorage = value; }
}

public static bool addUser(string name, string password);
public static bool delecteUser();//只能删除当前登录的用户
public static bool alterUser(string oldName, string oldPassword, string newName, string newPassword);

}

上面是读取函数,下面是写入函数,自己慢慢看看吧。
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");
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-11-14
这种具体的API问题,查MSDN吧本回答被网友采纳
相似回答