获取软件在注册表的安装信息
2013-08-14 18:39
405 查看
/// <summary> /// 获取软件在注册表的安装信息 /// 软件都会在这个注册表下填写自己的安装信息 /// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths /// </summary> /// <param name="softName">软件名称</param> /// <param name="path">返回软件安装路径</param> /// <returns>是否找到注册表的安装路径</returns> public static bool TryGetSoftwarePath(string softName, out string path) { string strPathResult = string.Empty; string strKeyName = ""; //"(Default)" key, which contains the intalled path object objResult = null; Microsoft.Win32.RegistryValueKind regValueKind; Microsoft.Win32.RegistryKey regKey = null; Microsoft.Win32.RegistryKey regSubKey = null; try { //Read the key regKey = Microsoft.Win32.Registry.LocalMachine; regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + softName.ToString() + ".exe", false); //Read the path objResult = regSubKey.GetValue(strKeyName); regValueKind = regSubKey.GetValueKind(strKeyName); //Set the path if (regValueKind == Microsoft.Win32.RegistryValueKind.String) { strPathResult = objResult.ToString(); } } catch (System.Security.SecurityException ex) { throw new System.Security.SecurityException("You have no right to read the registry!", ex); } catch (Exception ex) { throw new Exception("Reading registry error!", ex); } finally { if (regKey != null) { regKey.Close(); regKey = null; } if (regSubKey != null) { regSubKey.Close(); regSubKey = null; } } if (strPathResult != string.Empty) { //Found path = strPathResult; return true; } else { //Not found path = null; return false; } }
相关文章推荐
- 获取软件在注册表的安装信息
- C++访问注册表获取已安装软件信息列表示例代码
- C++访问注册表获取已安装软件信息列表示例代码
- c#获取软件在注册表中的安装信息
- C++通过访问注册表获取已安装软件信息列表
- C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件
- 函数打开注册表,获得安装软件的信息
- 获取未安装apk的软件包信息
- 利用C#访问注册表获取软件的安装路径
- 一个获取计算机硬件信息和安装软件清单的脚本
- Android获取系统已安装应用软件程序(apk)信息
- 获取所有安装在手机上的应用软件的信息
- 利用注册表获取本机安装的软件
- c#获取安装的软件和路径(注册表)
- C#读取注册表,获取本机安装的软件清单
- Android获取系统已安装应用软件程序(apk)信息
- C#读取注册表,获取本机安装的软件清单
- 获取所有已安装软件以及获取应用程序版本信息
- C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件
- C# 获取常见软件的安装路径(调用注册表)