当防火墙拒绝互联网访问时,ShellExecute 会阻止(永不返回)
我一直在使用 ShellExecute 在浏览器中打开 URL,从模态窗口代码调用,如下所示:
procedure TfmAbout1.BtnHomePageClick(Sender: TObject);
begin
inherited;
if ConnectedToWeb then
ShellExecute(Handle, 'open', URL_PRODUCT_HOMEPAGE, nil, nil, SW_SHOWNORMAL);
end;
但是在具有区域警报防火墙的计算机上,用户可能会收到弹出提示允许或拒绝我的应用程序访问互联网。当用户单击“拒绝”时,ShellExecute
永远不会返回...然后我的应用程序被挂起并停止运行。该进程必须从外部关闭(即从任务管理器)。
我可以做什么来预测或防止这种情况发生?我需要像 ShellExecute 这样的东西,在这种情况下是非阻塞的。
我将不胜感激任何想法。
I've been using ShellExecute
to open URLs in a browser, invoked from a modal windows' code, like this:
procedure TfmAbout1.BtnHomePageClick(Sender: TObject);
begin
inherited;
if ConnectedToWeb then
ShellExecute(Handle, 'open', URL_PRODUCT_HOMEPAGE, nil, nil, SW_SHOWNORMAL);
end;
But on machines with the Zone Alarm firewall, the user may get a pop-up prompt to allow or deny my application access to the Internet. When the user clicks "Deny", then ShellExecute
never returns... my application is then hung & the process has to be shut down externally (i.e., from Task Manager).
What can I do to either anticipate or prevent this? I need something like a ShellExecute
that is non-blocking in this situation.
I'd appreciate any ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想解决区域警报中的错误吗?
我可能会检查区域警报版本,并根据它,让一个小的“引导”程序代表我执行 ShellExecute。那只会挂起小型引导程序。
如果引导程序在超时(15 或 30 秒即可)后没有返回,您可以杀死该引导程序(因为您的父进程是所有者)。
您甚至可以警告用户,Zone Alarm 的版本有问题:)
编辑: 注意:我认为终止进程比终止线程更安全。
So you want to work around a bug in Zone Alarm?
I'd probably check for the Zone Alarm version, and depending on it, have a small 'bootstrap' program perform the ShellExecute on my behalf. That would only hang the small bootstrap program.
You could kill that bootstrap program (since your parent process is the owner) if it hasn't returned after a time out (15 or 30 seconds would do).
You could even warn the user that is has a buggy version of Zone Alarm :)
Edit: Note: I think killing a process is safer than killing a thread.
好吧,在线程中运行 ShellExecute。过一段时间你就可以看到它是否完成。如果没有,您可以终止它。
Well, run ShellExecute in a thread. In some time you could see if it completed or not. If not, you could just terminate it.