如何检测 Windows 防火墙是否正在请求用户许可
我们正在开发一个侦听某些端口的应用程序。我们确实想避免使用正确的安装程序,因此此时我们无法打开防火墙。
应用程序首次运行时,Windows 会弹出一个对话框,询问用户许可。此时,我们希望延迟执行,直到用户单击“是”(或就此而言“否”)。
目前我们使用类似:
while(FindWindow("Windows Security Alert")) {
Sleep(1000);
}
..它有效,但不是坚如磐石。据我所知, 防火墙 api< /a> 不提供此信息。
额外问题:是否还有一种方法可以检测用户是否单击了“是”或“否”?
We're working on an application that listens on some ports. We really want to avoid using a proper installer, so we can't open the firewall at that point.
First time the application runs, Windows pops up a dialog, asking the user for permission. At this point, we want to delay execution until the user has clicked yes (or no, for that matter).
At present we use something like:
while(FindWindow("Windows Security Alert")) {
Sleep(1000);
}
..which works, but isn't rock solid. As far as i can tell, the firewall api doesn't offer this information.
Bonus question: Is there also a way to detect whether the user clicked yes or no?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里您可以找到一些有关如何在 C# 代码中自行打开文件墙端口的代码 http: //www.shafqatahmed.com/2008/01/controlling-win.html
当然,您的应用程序必须以提升的速度运行才能执行此操作。
网络上也有几个安装程序提供此功能。例如(不幸的是不是开源的):uTorrent 的安装程序。
Here you can find some code on how to open the filewall port yourself in C# code http://www.shafqatahmed.com/2008/01/controlling-win.html
Of course your app must be running elevated in order to do this.
There are several installers on the web too which offer this functionality. For example (unfortunately not open source): uTorrent's installer.