c# - 读取注册表信息
来源:互联网 发布:java局部变量初始化 编辑:程序博客网 时间:2024/05/20 11:49
使用c# Microsoft.Win32.Registry 可以很简单的对注册表进行读写, 同时此API还支持修改Remote Machine的注册表信息。
请看代码:
using Microsoft.Win32; //regLocation:@"SOFTWARE\XXXX\EnvSetterServer" //keyName:TestAgentConfigPath public static string ReadRegistryKey(string regLocation, string keyName) { string keyValue = null; try { RegistryKey rk = Registry.LocalMachine.CreateSubKey(regLocation); if (rk.GetValue(keyName) != null) { keyValue = rk.GetValue(keyName).ToString(); } return keyValue; } catch (Exception ex) { return null; throw ex; } } //regLocation:@"SOFTWARE\XXXX\EnvSetterServer" //keyName:TestAgentConfigPath //keyValue:@"c:\tete\tete.exe" public static void WriteAKeyToRegistry(string regLocation, string keyName, string keyValue) { try { RegistryKey rk = Registry.LocalMachine.CreateSubKey(regLocation); rk.SetValue(keyName, keyValue, RegistryValueKind.String); rk.Close(); } catch (Exception ex) { throw ex; } } //remoteMachine:MachineName //regLocation:@"SOFTWARE\XXXX\EnvSetterServer" //keyName:TestAgentConfigPath public static string ReadRemoteRegistryKey(string remoteMachine, string regLocation, string keyName) { string keyValue = null; try { RegistryKey rk = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, remoteMachine).OpenSubKey(regLocation); if (rk.GetValue(keyName) != null) { keyValue = rk.GetValue(keyName).ToString(); } return keyValue; } catch (Exception ex) { return null; throw ex; } }
详细信息可以参考:http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx
- C#读取注册表信息
- c# - 读取注册表信息
- C#读取注册表信息
- C#读取注册表信息
- C# 读取Windows注册表信息
- 使用C#如何写入/读取注册表信息
- 使用C#如何写入/读取注册表信息
- JS读取注册表信息!!!
- 注册表读取CPU信息
- C#中,用注册表存储和读取信息
- 用C#读取注册表信息
- 用C#读取注册表信息
- java读取注册表中的信息
- windows下面读取注册表信息
- C# 操作注册表 写入注册表 修改注册表 读取注册表
- C# 操作注册表 写入注册表 修改注册表 读取注册表
- c++ 读注册表信息 读取CPU信息
- C#读取注册表中的数据:
- 天外有天——一代棋圣吴清源自传(1)
- 从M个数中选择前N大的数
- 天外有天——一代棋圣吴清源自传(2)
- shell语法小结
- 黑马程序员_异常try,catch处理
- c# - 读取注册表信息
- 天外有天——一代棋圣吴清源自传(3)
- oracle 左连接 还是右连接
- Android JNI(实现自己的JNI_OnLoad函数)
- 利用FilterDesigner设计滤波器
- 2.构建一个简单的文本编辑器
- MMFShare
- Bitvise Tunnelier 连接上一会儿就会掉。
- 学习ext4.0的经验