C# 读写注册表
2015-05-20 15:59
239 查看
/// <summary>
/// 获得要找到的注册表项
/// </summary>
/// <param name="path">注册表路经</param>
/// <returns>返回注册表对象</returns>
public bool CreateItemRegEdit(string path)
{
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
obj.CreateSubKey(path);
return true;
}
catch (Exception e)
{
return false;
}
}
/// <summary>
/// 设置注册表项下面的值
/// </summary>
/// <param name="path">路经</param>
/// <param name="name">名称</param>
/// <param name="value">值</param>
/// <returns>是否成功</returns>
public int SetValueRegEdit(string path ,string name ,string value)
{
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey objItem = obj.OpenSubKey(path,true);
objItem.SetValue(name, value);
}
catch (Exception e)
{
return 0;
}
return 1;
}
/// <summary>
/// 查看注册表指定项的值
/// </summary>
/// <param name="path">路经</param>
/// <param name="name">项名称</param>
/// <returns>项值</returns>
public string getValueRegEdit(string path, string name)
{
string value ;
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey objItem = obj.OpenSubKey(path);
value = objItem.GetValue(name).ToString();
}
catch (Exception e)
{
return "";
}
return value;
}
/// <summary>
/// 查看注册表项是否存在
/// </summary>
/// <param name="value">路经</param>
/// <param name="name">项名称</param>
/// <returns>是否存在</returns>
public bool SearchItemRegEdit(string path,string name)
{
string[] subkeyNames;
Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path);
subkeyNames = software.GetSubKeyNames();
//取得该项下所有子项的名称的序列,并传递给预定的数组中
foreach (string keyName in subkeyNames) //遍历整个数组
{
if (keyName.ToUpper() == name.ToUpper()) //判断子项的名称
{
hkml.Close();
return true;
}
}
hkml.Close();
return false;
}
/// <summary>
/// 查看注册表的值是否存在
/// </summary>
/// <param name="value">路经</param>
/// <param name="value">查看的值</param>
/// <returns>是否成功</returns>
public bool SearchValueRegEdit(string path,string value)
{
string[] subkeyNames;
Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path);
subkeyNames = software.GetValueNames();
//取得该项下所有键值的名称的序列,并传递给预定的数组中
foreach (string keyName in subkeyNames)
{
if (keyName.ToUpper() == value.ToUpper()) //判断键值的名称
{
hkml.Close();
return true;
}
}
hkml.Close();
return false;
}
/// 获得要找到的注册表项
/// </summary>
/// <param name="path">注册表路经</param>
/// <returns>返回注册表对象</returns>
public bool CreateItemRegEdit(string path)
{
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
obj.CreateSubKey(path);
return true;
}
catch (Exception e)
{
return false;
}
}
/// <summary>
/// 设置注册表项下面的值
/// </summary>
/// <param name="path">路经</param>
/// <param name="name">名称</param>
/// <param name="value">值</param>
/// <returns>是否成功</returns>
public int SetValueRegEdit(string path ,string name ,string value)
{
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey objItem = obj.OpenSubKey(path,true);
objItem.SetValue(name, value);
}
catch (Exception e)
{
return 0;
}
return 1;
}
/// <summary>
/// 查看注册表指定项的值
/// </summary>
/// <param name="path">路经</param>
/// <param name="name">项名称</param>
/// <returns>项值</returns>
public string getValueRegEdit(string path, string name)
{
string value ;
try
{
Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey objItem = obj.OpenSubKey(path);
value = objItem.GetValue(name).ToString();
}
catch (Exception e)
{
return "";
}
return value;
}
/// <summary>
/// 查看注册表项是否存在
/// </summary>
/// <param name="value">路经</param>
/// <param name="name">项名称</param>
/// <returns>是否存在</returns>
public bool SearchItemRegEdit(string path,string name)
{
string[] subkeyNames;
Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path);
subkeyNames = software.GetSubKeyNames();
//取得该项下所有子项的名称的序列,并传递给预定的数组中
foreach (string keyName in subkeyNames) //遍历整个数组
{
if (keyName.ToUpper() == name.ToUpper()) //判断子项的名称
{
hkml.Close();
return true;
}
}
hkml.Close();
return false;
}
/// <summary>
/// 查看注册表的值是否存在
/// </summary>
/// <param name="value">路经</param>
/// <param name="value">查看的值</param>
/// <returns>是否成功</returns>
public bool SearchValueRegEdit(string path,string value)
{
string[] subkeyNames;
Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path);
subkeyNames = software.GetValueNames();
//取得该项下所有键值的名称的序列,并传递给预定的数组中
foreach (string keyName in subkeyNames)
{
if (keyName.ToUpper() == value.ToUpper()) //判断键值的名称
{
hkml.Close();
return true;
}
}
hkml.Close();
return false;
}
相关文章推荐
- C#读写注册表
- C#读写注册表操作类
- C#中关于文件读写操作和注册表操作
- (转)【VS调试】C#读写Windows 7注册表时抛出“不允许所请求的注册表访问权”的解决办法
- C#读写注册表
- C#对注册表读写类的再封装
- 易语言写DLL给C#调用读写注册表
- c#读写注册表示例分享
- C#注册表读写完整操作类
- C#读写注册表的一些资料
- C#中对注册表的操作 读写注册表方法
- Operating the registry help class(C#读写注册表操作)
- C#读写注册表
- C#对注册表读写类的再封装
- c# 读写注册表
- 【VS调试】C#读写Windows 7注册表时抛出“不允许所请求的注册表访问权”的解决办法
- [转载]c#读写注册表
- C# 32位/64位系统下程序读写注册表之差异
- c#读写注册表示例分享
- C#读写注册表 二进制写入