用C#去获取注册表里的值
来源:互联网 发布:ubuntu双系统磁盘分区 编辑:程序博客网 时间:2024/06/05 19:36
static RegInfo getRegInfo(bool wow64)
{
string regKeyName;
// Check registry in both 32 and 64
if (wow64)
{
regKeyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" + productCode;
}
else
{
regKeyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + productCode;
}
var result = new RegInfo();
//// Use this to avoid always get null, see http://stackoverflow.com/questions/9491958/registry-getvalue-always-return-null
//RegistryKey localKey;
//if (Environment.Is64BitOperatingSystem)
// localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
//else
// localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
//result.DisplayName = localKey.OpenSubKey(regKeyName)?.GetValue("DisplayName", null) as string;
//result.DisplayVersion = localKey.OpenSubKey(regKeyName)?.GetValue("DisplayVersion", null) as string;
//通过前面的路径去取DisplayName的value,后面一个参数是取不到时,就返回这个参数
result.DisplayName = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + regKeyName, "DisplayName", null) as string;
result.DisplayVersion = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + regKeyName, "DisplayVersion", null) as string;
return result;
}
{
string regKeyName;
// Check registry in both 32 and 64
if (wow64)
{
regKeyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" + productCode;
}
else
{
regKeyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + productCode;
}
var result = new RegInfo();
//// Use this to avoid always get null, see http://stackoverflow.com/questions/9491958/registry-getvalue-always-return-null
//RegistryKey localKey;
//if (Environment.Is64BitOperatingSystem)
// localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
//else
// localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
//result.DisplayName = localKey.OpenSubKey(regKeyName)?.GetValue("DisplayName", null) as string;
//result.DisplayVersion = localKey.OpenSubKey(regKeyName)?.GetValue("DisplayVersion", null) as string;
//通过前面的路径去取DisplayName的value,后面一个参数是取不到时,就返回这个参数
result.DisplayName = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + regKeyName, "DisplayName", null) as string;
result.DisplayVersion = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + regKeyName, "DisplayVersion", null) as string;
return result;
}
阅读全文
0 0
- 用C#去获取注册表里的值
- 注册表里的猫腻
- 注册表里的秘密
- 保存程序配置的方法:保存到注册表里 - C#
- 注册表里的一些技巧
- 注册表里的一些技巧
- 删除注册表里的JDK
- 注册表里注册自己的协议
- 注册表里注册自己的协议
- 用installshield打包时在注册表里注册项和键值的动态设定方法
- 用installshield打包时在注册表里注册项和键值的动态设定方法
- 从注册表里搜寻安装的串口
- wince 注册表里的一些技巧
- 在注册表里删除没用的服务
- DB2获取表里所有的列
- 为什么系统重启后注册表里写的信息就不见了?
- 注意Windows注册表里加载的病毒和流氓软件!
- xp,windows2000/2003/2008注册表里ipv6地址的位置
- 习题6.5
- 远程显示(操作) 服务器 GUI 程序(图形化界面) (基于 X11 Forwarding + Centos + MobaXterm)
- Zookeeper介绍(一)——背景知识
- 用break退出方法和跑异常的退出递归
- 如何打败拖延症?
- 用C#去获取注册表里的值
- Zookeeper介绍(二)——Zookeeper概述
- 【第六届蓝桥杯】隔行变色
- 一.08异常
- 华为交换机设置vlan trunk口 并保存设置
- Spring Cloud构建微服务架构—服务消费基础
- 1053. 住房空置率 (20)
- Java多线程编程-(20)-借ThreadLocal出现OOM内存溢出问题再谈弱引用WeakReference
- Zookeeper介绍(三)——Zookeeper的安装