原文  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是否已安装,通过注册表

 代码如下 复制代码

#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

asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装)的更多相关文章

  1. 使用.NET 4.0+ 操作64位系统中的注册表

    一.64位系统中的注册表 以 LocalMachine 中的启动项为例: 64位应用的注册表位置还是在: SOFTWARE\Microsoft\Windows\CurrentVersion\Run 而 ...

  2. C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation

    C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation 后台添加以下方法:/// <summa ...

  3. Unity中对注册表进行修改

    问题背景: PC端软件开发,当我在Unity中的PlayerSetting中设置好分辨率,每次打包运行后会记忆上次退出时窗口的分辨率(记忆窗口状态),导致下次打开时不是PlayerSetting中的初 ...

  4. 用 C# 在 Windows 7 中写注册表想到的

    摘自:http://blog.163.com/dpj_001/blog/static/2742941520110251500753/ 某日做一个项目,需要在注册表中加入键,同时写值,操作系统环境为 W ...

  5. Ruby Rails学习中:注册表单,注册失败,注册成功

    接上篇 一. 注册表单 用户资料页面已经可以访问了, 但内容还不完整.下面我们要为网站创建一个注册表单. 1.使用 form_for 注册页面的核心是一个表单, 用于提交注册相关的信息(名字.电子邮件 ...

  6. 在Unity中对注册表的信息进行操作

      问题1 在对注册表进行操作时无法生成注册表相关的类  解决办法:     增加头文件using Microsft.Win32; 问题2                    在运行程序时报错同时注 ...

  7. 使用MSBUILD 构建时出错 error MSB3086: 任务未能使用 SdkToolsPath“”或注册表项“XXX”找到“LC.exe”,请确保已设置 SdkToolsPath。

    如果项目有添加有WB引用,比如引用其它网站的WEB服务等,那么VS在编译时会自动生成个 [项目名称].Serializers.dll的文件,就是把引用服务中的相关对象信息生成硬编码的程序集,以提高效率 ...

  8. ASP.NET中后台注册js脚本攻略(转)

    用Page.ClientScript.RegisterClientScriptBlock 和Page.ClientScript.RegisterStartupScript:区别:   1.使用Page ...

  9. asp.net中通过form表单submit提交到后台的实例

    前台<body>中的代码: <body> <div id="top"> </div> <form id="login ...

随机推荐

  1. jquery倒计时自动跳转

    刚开始我用下面这种方法一直报错,不知是什么原因,就是多加了页面加载时调用这个方法,还请高手看到后小小留言解惑

  2. vim 小技巧总结

    1.v+移动光标可以选中文本. 2.y可以复制已经选中的文本 3.p可以粘贴 复制一行则:yy 复制当前光标所在的位置到行尾:y$ 复制当前光标所在的位置到行首:y^ 复制三行则:3yy,即从当前光标 ...

  3. tabbar动画切换

    效果1: UIViewController *vc = self.viewControllers[self.selectedIndex]; CATransition *animation =[CATr ...

  4. swift-数组array

    // Playground - noun: a place where people can play import UIKit //--------------------------------- ...

  5. Jetty:配置概览-须要配置什么

    上一节讲述了怎么配置Jetty,这节将告诉你使用Jetty你须要配置些什么. 配置Server Server实例是Jetty服务端的中心协调对象,它为全部其它Jetty服务端组件提供服务和生命周期管理 ...

  6. 亚马逊带Marketplace product code的image无法再mount到其他镜像上

    这是对已发布镜像的保护么?难道对其进行修改的路彻底断掉了? 以volume形式attach也不行,dd成raw再读取也读不了,敢问路在何方呢 If a volume has an AWS Market ...

  7. BZOJ 1057: [ZJOI2007]棋盘制作( dp + 悬线法 )

    对于第一问, 简单的dp. f(i, j)表示以(i, j)为左上角的最大正方形, f(i, j) = min( f(i + 1, j), f(i, j + 1), f(i + 1, j + 1)) ...

  8. xp对opengl的支持问题

    我在项目中遇到的xp显示问题是因为xp对opengl的支持问题,是通过void QCoreApplication::setAttribute(Qt::ApplicationAttribute attr ...

  9. 我的Android进阶之旅------>HTTP 返回状态值详解

    (本文转载于:http://blog.csdn.net/ithomer/article/details/10240351) 当用户点击或搜索引擎向网站服务器发出浏览请求时,服务器将返回Http Hea ...

  10. C/C++迭代器使用具体解释

    迭代器是一种检查容器内元素并遍历元素的数据类型.能够替代下标訪问vector对象的元素. 每种容器类型都定义了自己的迭代器类型,如 vector: vector<int>::iterato ...