CefSharp 是一个非常不错的cef封装。但它依赖于VC++环境。

具体如下:

Branch CEF Version VC++ Version .Net Version Status
master 3202 2013 4.5.2 Development
cefsharp/62 3202 2013 4.5.2 Pre-Release
cefsharp/57 2987 2013 4.5.2 Release
cefsharp/55 2883 2013 4.5.2 Unsupported
cefsharp/53 2785 2013 4.5.2 Unsupported
cefsharp/51 2704 2013 4.5.2 Unsupported
cefsharp/49 2623 2013 4.0 Unsupported
cefsharp/47 2526 2013 4.0 Unsupported
cefsharp/45 2454 2013 4.0 Unsupported
cefsharp/43 2357 2012 4.0 Unsupported
cefsharp/41 2272 2012 4.0 Unsupported
cefsharp/39 2171 2012 4.0 Unsupported
cefsharp/37 2062 2012 4.0 Unsupported
 

于是我们在初始化cef前需要先检测vc++环境情况。

通过检测注册表方式,具体实现代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public static bool IsInstallVc2013x86()
       {
           try
           {
               Microsoft.Win32.RegistryKey uninstallNode = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
 
               foreach (string subKeyName in uninstallNode.GetSubKeyNames())
               {
                   Microsoft.Win32.RegistryKey subKey = uninstallNode.OpenSubKey(subKeyName);
                   object BundleProviderKey = subKey.GetValue("BundleProviderKey");
                   if (BundleProviderKey != null)
                   {
                       //HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{ 5e4b593b - ca3c - 429c - bc49 - b51cbf46e72a}
                       //HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{13A4EE12-23EA-3371-91EE-EFB36DDFFF3E} 中文版本
                       if (BundleProviderKey.ToString() == "{5e4b593b-ca3c-429c-bc49-b51cbf46e72a}")
                       {
                           return true;
                           // MessageBox.Show(displayName.ToString());  
                       }
                       //if (BundleProviderKey.ToString() == "{f65db027-aff3-4070-886a-0d87064aabb1}")  英文版
                       //{
                       //    return true;
                       //    // MessageBox.Show(displayName.ToString());  
                       //}
                   }
               }
           }
           catch (Exception ex)
           {
 
               //LogTextHelper.Error(ex);
           }
 
           return false;
       }

  

当为检测到未安装时,提示用户安装。

用户选择确认后,以管理员方式执行安装文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
private static bool InitVc2013x86()
{
    try
    {
        if (!IsInstallVc2013x86())
        {
            //http://www.microsoft.com/zh-cn/download/details.aspx?id=40784
 
            //LogTextHelper.Error("系统未安装Vc2013x86组件");
 
            Splasher.Show(typeof(frmSysSplash));
 
            Splasher.Status = string.Format("首次使用,正在检测系统组件...");
            System.Threading.Thread.Sleep(10000);
 
            Splasher.Close();
 
            MessageUtil.ShowTips("检测到您的机器未安装Microsoft Visual C++ 2013运行组件,系统将为您自动安装。");
 
            Splasher.Show(typeof(frmSysSplash));
            Splasher.Status = string.Format("正在安装系统组件,请耐心等待...");
 
 
            int duration = 10000;
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间
            string installMessage = string.Empty;
            bool installSucces = InstallVc2013x86(out installMessage);
            stopwatch.Stop(); //  停止监视
            if (installSucces)//安装成功
            {
                if (stopwatch.Elapsed.TotalMilliseconds < duration)
                {
                    int total = duration - (int)stopwatch.Elapsed.TotalMilliseconds;
                    int step = 30;
                    while (true)
                    {
                        System.Threading.Thread.Sleep(200);
                        Splasher.Status = string.Format("当前进度{0}%...", 100 * step / total);
                        step += 200;
                        if (step > total)
                        {
                            break;
                        }
                    }
                }
 
                Splasher.Status = string.Format("操作完成!正在验证安装...");
                System.Threading.Thread.Sleep(3000);
                Splasher.Close();
 
                if (!IsInstallVc2013x86())//校验安装
                {
                    if (MessageBox.Show("自动安装失败!您可以尝试以管理员身份重新打开或从以下网站手动下载安装。(http://www.microsoft.com/zh-cn/download/details.aspx?id=40784)""提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start("http://www.microsoft.com/zh-cn/download/details.aspx?id=40784");
                    }
                    return false;
                }
                return true;
            }
            else
            {
                Splasher.Close();
                MessageUtil.ShowTips(installMessage);
                return false;
            }
        }
 
        //LogTextHelper.Error("已安装环境");
        return true;
    }
    catch (Exception ex)
    {
        //LogTextHelper.Error(ex);
    }
    return false;
}
 
 
public static bool InstallVc2013x86(out string message)
{
    message = string.Empty;
    string fileName = System.IO.Path.Combine(Application.StartupPath, "vcredist_x86\\vcredist_x86.exe");
    if (!System.IO.File.Exists(fileName))
    {
        //LogTextHelper.Info("未找到文件 " + fileName);
        message = "未找到文件" + fileName;
        return false;
    }
 
    /**
  * 当前用户是管理员的时候,直接启动应用程序
  * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行
  */
    //获得当前登录的Windows用户标示
    System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
    System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
 
    //LogTextHelper.Info("开始安装 InstallVc2013x86");
    //判断当前登录用户是否为管理员
    if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
    {
        //LogTextHelper.Info("当前身份为管理员");
        //LogTextHelper.Info("管理员方式运行");
        //LogTextHelper.Info("开始安装 InstallVc2013x86");
        System.Diagnostics.Process.Start(fileName).WaitForExit();
    }
    else
    {
        //LogTextHelper.Info("管理员方式运行");
        //LogTextHelper.Info("开始安装 InstallVc2013x86");
        //创建启动对象
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        //设置运行文件
        startInfo.FileName = fileName;
        //设置启动参数
        //startInfo.Arguments = String.Join(" ", Args);
        //设置启动动作,确保以管理员身份运行
        startInfo.Verb = "runas";
        //如果不是管理员,则启动UAC
 
        System.Diagnostics.Process.Start(startInfo).WaitForExit();
    }
    return true;
}

  

应用程序入口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
 
    InitPlugins();
    if (!InitVc2013x86())
    {
        return;
    }
    if (!InitCef())
    {
        MessageUtil.ShowError("主界面初始化失败!");
        return;
    }
    Application.Run(new FrmFirst());
}

  

附录vc++各版本 检查方法:

Visual C++ 2005

Microsoft Visual C++ 2005 Redistributable (x64)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1af2a8da7e60d0b429d7e6453b3d0182
Configuration: x64
Version: 6.0.2900.2180

Direct Download URL: https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE

Microsoft Visual C++ 2005 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\c1c4f01781cc94c4c8fb1542c0981a2a
Configuration: x86
Version: 6.0.2900.2180

Direct Download URL: https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE


Visual C++ 2008

Microsoft Visual C++ 2008 Redistributable (x64)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\67D6ECF5CD5FBA732B8B22BAC8DE1B4D
Configuration: x64
Version: 9.0.30729.5677

Direct Download URL: https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe

Microsoft Visual C++ 2008 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\6E815EB96CCE9A53884E7857C57002F0
Configuration: x86
Version: 9.0.30729.5677

Direct Download URL: https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x86.exe


Visual C++ 2010

Microsoft Visual C++ 2010 Redistributable (x64)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1926E8D15D0BCE53481466615F760A7F
Configuration: x64
Version: 10.0.40219.325

Direct Download URL: https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe

Microsoft Visual C++ 2010 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Products\1D5E3C0FEDA1E123187686FED06E995A
Configuration: x86
Version: 10.0.40219.325

Direct Download URL: https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe


Visual C++ 2012

Microsoft Visual C++ 2012 Redistributable (x64)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}
Configuration: x64
Version: 11.0.61030.0

Direct Download URL: https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe

Microsoft Visual C++ 2012 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}
Configuration: x86
Version: 11.0.61030.0

Direct Download URL: https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe


Visual C++ 2013

Microsoft Visual C++ 2013 Redistributable (x64)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{050d4fc8-5d48-4b8f-8972-47c82c46020f}
Configuration: x64
Version: 12.0.30501.0

Direct Download URL: https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe

Microsoft Visual C++ 2013 Redistributable (x86)
Registry Key: HKLM\SOFTWARE\Classes\Installer\Dependencies\{f65db027-aff3-4070-886a-0d87064aabb1}
Configuration: x86
Version: 12.0.30501.0

Direct Download URL: https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe


Visual C++ 2015

Microsoft Visual C++ 2015 Redistributable (x64) - 14.0.24215
Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{d992c12e-cab2-426f-bde3-fb8c53950b0d}
Configuration: x64
Version: 14.0.24215.1

Direct Download URL: https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe

Microsoft Visual C++ 2015 Redistributable (x86) - 14.0.24215
Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{e2803110-78b3-4664-a479-3611a381656a}
Configuration: x86
Version: 14.0.24215.1

Direct Download URL: https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x86.exe


Visual C++ 2017

Caveat: There's either a new 2017 registry convention being used, or it hasn't been finalized, yet. As I'm guessing the upper-most keys of: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,amd64,14.0,bundle] and [HKEY_CLASSES_ROOT\Installer\Dependencies\,,x86,14.0,bundle]

are subject to change, or at least have different nested GUIDs, I'm going to use list the key that ends with a GUID.

Microsoft Visual C++ 2017 Redistributable (x64) - 14.11.25325
Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,amd64,14.0,bundle\Dependents\{6c6356fe-cbfa-4944-9bed-a9e99f45cb7a}]
Configuration: x64
Version: 14.11.25325.0

Direct Download URL: https://download.visualstudio.microsoft.com/download/pr/11100230/15ccb3f02745c7b206ad10373cbca89b/VC_redist.x64.exe

Microsoft Visual C++ 2017 Redistributable (x86) - 14.11.25325
Registry Key: [HKEY_CLASSES_ROOT\Installer\Dependencies\,,x86,14.0,bundle\Dependents\{404c9c27-8377-4fd1-b607-7ca635db4e49}]
Configuration: x86
Version: 14.11.25325.0

Direct Download URL: https://download.visualstudio.microsoft.com/download/pr/11100229/78c1e864d806e36f6035d80a0e80399e/VC_redist.x86.exe


Changelog
September 8th, 2017 -- Added 2017's version for 14.11.25325.0 as the new Visual C++ 2017 entry 
April 7th, 2017 -- Added for 2017's version of 14.10.25008.0 as the new Visual C++ 2017 entry 
October 24th, 2016 -- Updated for 2015's version info for 14.0.24215.1 
August 18th, 2016 -- Updated 2015's version info for 14.0.24212 
May 27th, 2016 -- Updated info for MSVC2015 Update 2

检测客户pc电脑端VC++环境并安装的更多相关文章

  1. 前端工程师须知pc电脑端分辨率

    PC端 按屏幕宽度大小排序(主流的用橙色标明) 分辨率   比例 | 设备尺寸 1024*500 (8.9寸) 1024*768 (比例4:3  | 10.4寸.12.1寸.14.1寸.15寸; ) ...

  2. PC电脑端支付宝扫码付款出现编码错误提示原因

    给这家公司做各大场景的支付 涉及到微信内置H5支付 其他浏览器唤醒微信客户端支付 PC扫码支付 和支付宝相应的支付,但今天进行PC扫码支付时遇到一些编码问题,流程能走通. 调试错误,请回到请求来源地, ...

  3. 浩瀚PDA无线POS盘点机(安装盘点程序):盘点结果实时上传到PC电脑端

    手持终端机的盘点部分改进, 1可以通过wifi联网到后台, 2也可以暂存在手持终端机上,盘点完后一次性上传到电脑上.

  4. VC环境下编译OpenSSL(仅仅是个示例,网上还有许多相关文章)

    VC环境OpenSSL安装以及编程过程 SSL就是Secure Sockets Layer,是一种安全套接字协议,详情请参考链接中的介绍. 配置过程中需要生成一些mak文件,这些生成代码用perl脚本 ...

  5. 检测到是移动端还是PC端进入页面,加载不同样式表现

    if(/AppleWebKit.*mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alc ...

  6. 20190418 CentOS7实用技能综合:系统安装 + WinScp客户端连接 + 防火墙端口号iptables + Nginx编译安装 + MySQL编译安装 + Redis编译安装 + MongoDB编译安装 + ActiveMQ/RocketMQ/RabbitMQ编译安装 + ...各类常用生产环境软件的编译安装

    系统安装 + WinScp客户端连接 + 防火墙端口号iptables + Nginx编译安装 + MySQL编译安装 + Redis编译安装 + MongoDB编译安装 + ActiveMQ/Roc ...

  7. Your wechat account may be LIMITED to log in WEB wechat, error info: <error><ret>1203</ret><message>为了你的帐号安全,此微信号不能登录网页微信。你可以使用Windows微信或Mac微信在电脑端登录。Windows微信下载地址:WeChat for PC

    转载:https://zhuanlan.zhihu.com/p/76180564 微信网页版限制登录或禁止登录将影响一大批使用itchat等Web Api方案的微信机器人 网页版微信 API 被封了, ...

  8. 移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签)

    移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签) 一.总结 一句话总结: 添加viewport标签:meta name="viewport" ...

  9. 支付宝支付-PC电脑网站支付

    支付产品全面升级(更新时间:2017/05/05 ),若您使用的是老接口,请移步老版本即时到账文档. 支持沙盒环境的测试 此项目已开源欢迎Start.PR.发起Issues一起讨论交流共同进步 htt ...

随机推荐

  1. day17-jdbc 7.Statement介绍

    SQL语句:DML.DQL.DCL.DDL.DML和DQL是用的最多的.DCL和DDL用的很少. 程序员一般是操作记录,创建一表很少. package cn.itcast.jdbc; import c ...

  2. Luogu 3292 [SCOI2016]幸运数字

    BZOJ 4568. 感觉很板. 前置技能:线性基.      放一篇感觉讲的比较丰富的博客: 戳这里. 首先要求在一个序列中任意选点使得异或和最大,当然是想到线性基了. 把问题转换到树上,如果每次询 ...

  3. js的学习

    对于 ff的 relatedTarget    及IE的toElement  fromElement DOM通过event对象的relatedTarget属性提供了相关元素的信息.这个属性只对于mou ...

  4. tab页以及jqgrid某些用法参考记录

    <%@ Page Language="C#" AutoEventWireup="True" CodeBehind="CcrCreditHuman ...

  5. 日常学习随笔-自定义了一个MyArrayListDefin集合(数组扩容+迭代器+JDK1.8新方法+详细说明)

    一.自定义了一个ArrayList的模拟集合(源码+详细说明) 前段时间分析了下ArrayList集合的源码,总觉得如果不自己定义一个的话,好像缺了点什么,所以有了如下的代码. 代码可以说是逐行注释了 ...

  6. Java流机制详解

    转自http://blog.csdn.net/qq_16558621/article/details/51377887  http://www.cr173.com/html/18666_1.html

  7. java读取classpath下properties文件注意事项

    1.properties文件在classpath根路径下读取方式 Properties properties = new Properties(); properties.load(BlogIndex ...

  8. SQL的发展史

    在20世纪60年代,网状数据库系统(如CODASYL)和分层数据库系统(如IMS TM)是用于自动化银行业务.记帐和订单处理系统的一流技术,这些系统是由于商业大型计算机的引入才启用的.而SQL是在70 ...

  9. webbrowser内容滚动(javascript内容无缝滚动)

    一 使用webbrowser现有方法 引用:https://blog.csdn.net/xiaokailele/article/details/48392673 public partial clas ...

  10. win10下安装配置mysql-8.0.13--实战可用

    1.下载mysql-8.0.13安装包 1 https://dev.mysql.com/downloads/mysql/ 选择zip安装包下载就好. 2.解压到你要安装的目录 3.创建my.ini配置 ...