如何在 VB.NET WebBrowser 遇到 SSL 错误(代理)时禁止打开默认浏览器? [英] How to suppress default browser from opening while VB.NET WebBrowser encounter SSL error (proxies) ?

查看:101
本文介绍了如何在 VB.NET WebBrowser 遇到 SSL 错误(代理)时禁止打开默认浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题.我有使用最新安装的 IE 引擎的应用程序.有时它可能会遇到问题,当它发生时,.NET 打开默认浏览器时出错(必须启用 SSL 才能与服务器连接,我正在使用代理).

I have small issue. I have application using latest installed IE engine. Sometimes it might encounter issue and when it's happen .NET opens default browser with error (that SSL has to be enabled to connect with server, I'm using proxies).

由于我的应用程序,我想禁止显示任何外部浏览器.

I want to suppress any external browsers from showing because of my application.

我知道我可以使用 Process.Start 启动浏览器并停止.但是如何识别新进程是由我的应用程序启动的(是否有进程或树的父进程?)

I know that I can start browser using Process.Start and stop. But how to recognise that new process is started by my application (is there any parent of process or Tree ?)

推荐答案

好的,下面介绍如何通过 WMI 包装器 System.Management

Ok, here's how you can retreive the PPID (parent process id) of any given process via the WMI wrapper System.Management

首先,您必须添加对System.Management的引用.

First you'll have to add a reference to System.Management obviously.

然后你必须查询有问题的进程:

Then you'll have to query for the process in question:

Dim pid As Int32 = Process.GetCurrentProcess.Id
Dim query As SelectQuery = New SelectQuery(String.Format("select * from Win32_Process where ProcessId = {0}", pid))

接下来,您需要将查询提供给ManagementObjectSearcher 并将结果放入ManagementObjectCollection

Next you need to feed the query to a ManagementObjectSearcher and put the results into a ManagementObjectCollection

Dim mobjSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(query)
Dim mobjProcesses As ManagementObjectCollection = mobjSearcher.Get()

最后选择第一个(希望也是唯一的)进程,它是 ParentProcessId

Finally select the first (and only, hopefully) process and it's ParentProcessId

Dim ppid As Int32 = mobjProcesses(0)("ParentProcessId")

不幸的是,ManagementObjectCollection知道它正在枚举什么类型的对象,因此您必须查找并转换它或对延迟绑定此时.

Unfortunatly the ManagementObjectCollection doesn't know what type of object it's enumerating, so you'll eighter have to look it up and cast it or be satisfied with late binding at this point.

当然,有一种方法可以通过 Windows API.这样你就必须调用 NtQueryInformationProcess 来自 ntdll.dll

There - of course - is a way to do this nativly via the Windows API. That way you'll have to call the NtQueryInformationProcess from the ntdll.dll

当调用函数时,你会传递一个 PROCESS_BASIC_INFORMATION 结构以及进程句柄等.

When calling the function you'd pass it a PROCESS_BASIC_INFORMATION struct along with the process handle and such.

成功返回后,您会在结构的 IntPtr InheritedFromUniqueProcessId 字段中找到父 PID(您必须将其转换为 Int32)

On successfull return you would find the parent PID in the IntPtr InheritedFromUniqueProcessId field of the stuct (which you'd have to cast to Int32)

既然我已经回答了问题我如何检索进程的父 PID",我才意识到这一点,尽管它可能会帮助您识别已启动的任何浏览器进程不情愿地被您的应用程序......这很可能不会消除所述应用程序的底层设计缺陷.

Now that I have answered the question "How do I retreive the parent PID of a process" I just realized that, though it might help you in your endevour to identify any browser process that is started unwillingly by your application... this most likly will not eliminate the underlying design flaw of said application.

这可能是 XY 问题

这篇关于如何在 VB.NET WebBrowser 遇到 SSL 错误(代理)时禁止打开默认浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆