asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装)

简介: 原文  asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装) 检测Office是否安装以及获取安装 路径 及安装版本  代码如下 复制代码     #region 检测Office是否安装     ///     /// 检测是否安装office     ...

原文  asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装)

检测Office是否安装以及获取安装 路径 及安装版本

 代码如下 复制代码

    #region 检测Office是否安装
     ///<summary>
     /// 检测是否安装office
     ///</summary>
     ///<param name="office_Version"> 获得并返回安装的office版本</param>
     ///<returns></returns>
     public static bool IsInstallOffice(out string office_Version, out string office_Path)
     {
         bool result = false;
         string str_OfficePath = string.Empty;
         string str_OfficeVersion = string.Empty;
         office_Version = string.Empty;
         office_Path = string.Empty;
 
         GetOfficePath(out str_OfficePath, out str_OfficeVersion);
         if (!string.IsNullOrEmpty(str_OfficePath) && !string.IsNullOrEmpty(str_OfficeVersion))
         {
             result = true;
             office_Version = str_OfficeVersion;
             office_Path = str_OfficePath;
         }
         return result;
     }
 
     ///<summary>
     /// 获取并返回当前安装的office版本和安装路径
     ///</summary>
     ///<param name="str_OfficePath">office的安装路径</param>
     ///<param name="str_OfficeVersion">office的安装版本</param>
     private static void GetOfficePath(out string str_OfficePath, out string str_OfficeVersion)
     {
         string str_PatheResult = string.Empty;
         string str_VersionResult = string.Empty;
         string str_KeyName = "Path";
         object objResult = null;
         Microsoft.Win32.RegistryValueKind regValueKind;//指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型。
         Microsoft.Win32.RegistryKey regKey = null;//表示 Windows 注册表中的项级节点(注册表对象?)
         Microsoft.Win32.RegistryKey regSubKey = null;
         try
         {
             regKey = Microsoft.Win32.Registry.LocalMachine;//读取HKEY_LOCAL_MACHINE项
             if (regSubKey == null)
             {//office97
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREMicrosoftOffice8.0CommonInstallRoot", false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开
                 str_VersionResult = "Office97";
                 str_KeyName = "OfficeBin";
             }
             if (regSubKey == null)
             {//Office2000
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREMicrosoftOffice9.0CommonInstallRoot", false);
                 str_VersionResult = "Pffice2000";
                 str_KeyName = "Path";
             }
             if (regSubKey == null)
             {//officeXp
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREMicrosoftOffice10.0CommonInstallRoot", false);
                 str_VersionResult = "OfficeXP";
                 str_KeyName = "Path";
             }
 
             if (regSubKey == null)
             {//Office2003
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREMicrosoftOffice11.0CommonInstallRoot", false);
                 str_VersionResult = "Office2003";
                 str_KeyName = "Path";
                 try
                 {
                     objResult = regSubKey.GetValue(str_KeyName);
                     regValueKind = regSubKey.GetValueKind(str_KeyName);
                 }
                 catch (Exception ex)
                 {
                     regSubKey = null;
                 }
             }
 
             if (regSubKey == null)
             {//office2007
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREMicrosoftOffice12.0CommonInstallRoot", false);
                 str_VersionResult = "Office2007";
                 str_KeyName = "Path";
             }
             objResult = regSubKey.GetValue(str_KeyName);
             regValueKind = regSubKey.GetValueKind(str_KeyName);
             if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
             {
                 str_PatheResult = objResult.ToString();
             }
         }
         catch (Exception ex)
         {
             LogHelper.WriteLogError(ex.ToString());
             //throw ex;
         }
         finally
         {
             if (regKey != null)
             {
                 regKey.Close();
                 regKey = null;
             }
 
             if (regSubKey != null)
             {
                 regSubKey.Close();
                 regSubKey = null;
             }
         }
         str_OfficePath = str_PatheResult;
         str_OfficeVersion = str_VersionResult;
     }
     #endregion

 

同理,检测QQ、Fetion、360杀毒、IE浏览器,Chrome、Office 2003/2007/2010

只需修改验证

1 regSubKey = regKey.OpenSubKey(@"SOFTWARETencentPlatForm_Type_List3", false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开
即可

检测QQ是否已安装,通过注册表

 代码如下 复制代码

View Code 
     #region 检测QQ是否安装
     public static bool isInstallQQ(out string QQVersion, out string QQPath)
     {
         bool result = false;
         string str_QQPath = string.Empty;
         string str_QQVersion = string.Empty;
         QQVersion = string.Empty;
         QQPath = string.Empty;
 
         GetQQPath(out str_QQPath, out str_QQVersion);
         if (!string.IsNullOrEmpty(str_QQPath) && !string.IsNullOrEmpty(str_QQVersion))
         {
             result = true;
             QQVersion = str_QQVersion;
             QQPath = str_QQPath;
         }
         return result;
     }
 
     /// <summary>
     /// 
     /// </summary>
     /// <param name="str_QQPath"></param>
     /// <param name="str_QQVersion"></param>
     private static void GetQQPath(out string str_QQPath, out string str_QQVersion)
     {
         string str_PatheResult = string.Empty;
         string str_VersionResult = string.Empty;
         string str_KeyName = "TypePath";
         object objResult = null;
         Microsoft.Win32.RegistryValueKind regValueKind;//指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型。
         Microsoft.Win32.RegistryKey regKey = null;//表示 Windows 注册表中的项级节点(注册表对象?)
         Microsoft.Win32.RegistryKey regSubKey = null;
         try
         {
             regKey = Microsoft.Win32.Registry.LocalMachine;//读取HKEY_LOCAL_MACHINE项
             if (regSubKey == null)
             {//QQ
                 regSubKey = regKey.OpenSubKey(@"SOFTWARETencentPlatForm_Type_List3", false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开
                 str_VersionResult = "QQ";
                 str_KeyName = "TypePath";
             }
             objResult = regSubKey.GetValue(str_KeyName);
             regValueKind = regSubKey.GetValueKind(str_KeyName);
             if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
             {
                 str_PatheResult = objResult.ToString();
             }
         }
         catch (Exception ex)
         {
             LogHelper.WriteLogError(ex.ToString());
             //throw ex;
         }
         finally
         {
             if (regKey != null)
             {
                 regKey.Close();
                 regKey = null;
             }
 
             if (regSubKey != null)
             {
                 regSubKey.Close();
                 regSubKey = null;
             }
         }
         str_QQPath = str_PatheResult;
         str_QQVersion = str_VersionResult;
     }
     #endregion

检测迅雷

 

 代码如下 复制代码
  #region 检测 Thunder 迅雷
     public static bool isInstallThunder(out string thunderVersion, out string thunderPath)
     {
         bool result = false;
         string str_ThunderPath = string.Empty;
         string str_ThunderVersion = string.Empty;
         thunderVersion = string.Empty;
         thunderPath = string.Empty;
 
         GetThunderPath(out str_ThunderPath, out str_ThunderVersion);
         if (!string.IsNullOrEmpty(str_ThunderPath) && !string.IsNullOrEmpty(str_ThunderVersion))
         {
             result = true;
             thunderVersion = str_ThunderVersion;
             thunderPath = str_ThunderPath;
         }
         return result;
     }
 
     /// <summary>
     /// 
     /// </summary>
     /// <param name="str_QQPath"></param>
     /// <param name="str_QQVersion"></param>
     private static void GetThunderPath(out string str_thunderPath, out string str_thunderVersion)
     {
         string str_PatheResult = string.Empty;
         string str_VersionResult = string.Empty;
         string str_KeyName = "Path";
         object objResult = null;
         Microsoft.Win32.RegistryValueKind regValueKind;//指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型。
         Microsoft.Win32.RegistryKey regKey = null;//表示 Windows 注册表中的项级节点(注册表对象?)
         Microsoft.Win32.RegistryKey regSubKey = null;
         try
         {
             regKey = Microsoft.Win32.Registry.LocalMachine;//读取HKEY_LOCAL_MACHINE项
             if (regSubKey == null)
             {//QQ
                 regSubKey = regKey.OpenSubKey(@"SOFTWAREThunder NetworkThunderOemthunder_backwnd", false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开
                 str_VersionResult = "Thunder";
                 str_KeyName = "Path";
             }
             objResult = regSubKey.GetValue(str_KeyName);
             regValueKind = regSubKey.GetValueKind(str_KeyName);
             if (regValueKind == Microsoft.Win32.RegistryValueKind.ExpandString)
             {
                 str_PatheResult = objResult.ToString();
             }
         }
         catch (Exception ex)
         {
             LogHelper.WriteLogError(ex.ToString());
         }
         finally
         {
             if (regKey != null)
             {
                 regKey.Close();
                 regKey = null;
             }
             if (regSubKey != null)
             {
                 regSubKey.Close();
                 regSubKey = null;
             }
         }
         str_thunderPath = str_PatheResult;
         str_thunderVersion = str_VersionResult;
     }
     #endregion
目录
相关文章
|
21小时前
|
开发框架 缓存 前端开发
安装ASP.NET AJAX (一安装)
安装ASP.NET AJAX (一安装)
11 0
|
21小时前
|
SQL Windows
保姆级:Windows Server 2012上安装.NET Framework 3.5
保姆级:Windows Server 2012上安装.NET Framework 3.5
|
22小时前
|
Windows
0基础安装激活版本office2016
0基础安装激活版本office2016
|
22小时前
|
Windows
windows server 2019 安装NET Framework 3.5失败,提示:“安装一个或多个角色、角色服务或功能失败” 解决方案
windows server 2019 安装NET Framework 3.5失败,提示:“安装一个或多个角色、角色服务或功能失败” 解决方案
253 0
|
22小时前
|
安全 C# 开发者
.NET开源的一键自动化下载、安装、激活Microsoft Office利器
.NET开源的一键自动化下载、安装、激活Microsoft Office利器
|
22小时前
|
监控 Ubuntu 安全
百度搜索:蓝易云【Ubuntu安装Net-tools和SSH】
请注意,这些命令假设您已经具有适当的网络连接,并具有sudo或root权限。根据您的具体环境和要求,可能需要进行其他配置和调整。确保在进行任何与网络和安全相关的操作之前,详细了解您的需求和网络环境,并采取适当的安全措施。
73 1
|
22小时前
云效静态代码检测可以检测.net吗?
云效静态代码检测可以检测.net吗?
31 1
|
22小时前
|
C# Windows
C#安装“Windows 窗体应用(.NET Framework)”
C#安装“Windows 窗体应用(.NET Framework)”
56 0
|
6月前
|
Oracle 关系型数据库 Linux
在CentOS 7 下安装.Net 框架
在CentOS 7 下安装.Net 框架
79 0
|
22小时前
微软Office 2019
微软办公软件套件Microsoft Office 2019 专业增强版2024年4月批量许可版更新推送!Office2019正式版2018年10月份推出,主要为多人跨平台办公与团队协作打造。Office2019整合对过去三年在Office365里所有功能,包括对Word、Excel、PowerPoint、Outlook、Project、Visio、Access、Publisher的更新。
28 2