C#读写注册表
请高手把本程序补充完整,如果你的电脑中有HKEY_LOCAL_MACHINE\SOFTWARE\Adobe和HKEY_LOCAL_MACHINE\SOFTWARE\QQ,没有可用其它代替。
目的:1、从这两个注册表项取出所有项和键值,存入一个txt文件。
2、 读出txt文件,写入注册表
using System;
using System.Collections.Generic;
using System.Text;
namespace IregOperate
{
/// <summary>
/// IRegOperator接口
/// </summary>
interface IRegOperator
{
/// <summary>
/// Read()方法
/// Write(list<string> content)方法
/// </summary>
/// <returns></returns>
string Read();
void Write(List<string> content);
}
/// <summary>
/// 抽象类AbstractRegOperate实现IRegOperator接口
/// </summary>
abstract class AbstractRegOperate : IRegOperator
{
public abstract string Read();
public abstract void Write(List<string> content);
protected string ReadRegistry(string registryname)
{
}
}
class UTRegOperator : AbstractRegOperate
{
public override string Read()
{
string temp = string.Empty;
temp += ReadRegistry(@"HKEY_LOCAL_MACHINE\SOFTWARE\Adobe");
return temp;
}
public override void Write(List<string> content)
{
throw new Exception("The method or operation is not implemented.");
}
}
class CTRegOperator : AbstractRegOperate
{
public override string Read()
{
string temp = string.Empty;
temp += ReadRegistry(@"HKEY_LOCAL_MACHINE\SOFTWARE\QQ");
return temp;
}
public override void Write(List<string> content)
{
}
}
public class RegOperatorFactory : IRegOperator
{
IRegOperator m_operator;
public RegOperatorFactory(RegOption option)
{
switch (option)
{
case RegOption.CT:
m_operator = new CTRegOperator();
break;
case RegOption.UT:
m_operator = new UTRegOperator();
break;
default:
throw new Exception("没有提供方法实现。");
}
}
public string Read()
{
return m_operator.Read();
}
public void Write(List<string> content)
{
m_operator.Write(content);
}
}
public enum RegOption
{
UT,
CT
}
}