向注册表中写东西

/// <summary>
/// 将记录的功能名称写入注册表 by vichin 2016.5.17
/// </summary>
/// <param name="functionNode"></param>
public void SetReg(string functionNode) {
RegistryKey key = Registry.LocalMachine;
RegistryKey portal = key.CreateSubKey("SOFTWARE\PICS\PORTAL");
portal.SetValue("PORTAL", functionNode);
portal.Close();
} 

这当中的地址,必须要有一个计算机生成的绝对地址,不能单单的写入由用户生成的地址

开始写了pics\portal,然并卵,后面加入了software就有用了,这software便是计算机中原本拥有的地址。

  

//将字符串从注册表中读取出来。
RegSetandRead RSR = new RegSetandRead();
string functionNode = string.Empty;
int i=0;
if (RSR.Exist(ref functionNode,ref i))
{
showLayout(functionNode,i); 
}

public class RegSetandRead
{
/// <summary>
/// 从注册表中找出用户上次退出的节点。 by vichin 2016.5.16
/// </summary>
/// <param name="functionNode"></param>
/// <returns></returns>
public bool Exist(ref string nodeName, ref int i)
{

RegistryKey pics = Registry.LocalMachine.OpenSubKey("SOFTWARE\PICS\PORTAL");
if (pics == null) 
return false; 
else
{
string functionNode = pics.GetValue("PORTAL").ToString();
string[] nameIndex = functionNode.Split(',');
nodeName = nameIndex[0];
int.TryParse(nameIndex[1], out i);
pics.Close();
return true;
}
}
/// <summary>
/// 将记录的功能名称写入注册表 by vichin 2016.5.17
/// </summary>
/// <param name="functionNode"></param>
public void SetReg(string functionNode)
{
RegistryKey key = Registry.LocalMachine;
RegistryKey portal = key.CreateSubKey("SOFTWARE\PICS\PORTAL");
portal.SetValue("PORTAL", functionNode);
portal.Close();
}
}
原文地址:https://www.cnblogs.com/vichin/p/5501409.html