简体   繁体   English

如何为我的应用程序显示“Windows 防火墙已阻止此程序的某些功能”对话框?

[英]how to display “Windows Firewall has blocked some features of this program” dialog for my app?

I'm developing .Net 4.0 C# Windows Forms app which hosts WCF service on some predefined port (let's say 12345).我正在开发 .Net 4.0 C# Windows 窗体应用程序,它在某个预定义的端口(比如 12345)上托管 WCF 服务。 We have another iPad app which talks to this WCF service - and this connection is blocked by windows firewall.我们有另一个与此 WCF 服务对话的 iPad 应用程序 - 此连接被 Windows 防火墙阻止。 My users always have troubles with it because they have to remember to add this app to exception list etc - which causes frustration.我的用户总是遇到麻烦,因为他们必须记住将此应用程序添加到例外列表等 - 这会导致沮丧。

What is required to make Windows to display popup like on the screenshot below for my app, to make it more user-friendly?需要什么才能使 Windows 在我的应用程序的下面屏幕截图中显示弹出窗口,以使其更加用户友好?

UPDATE - I do understand I can programatically update rules in Windows Firewall.更新- 我知道我可以以编程方式更新 Windows 防火墙中的规则。 However, that would require admin privileges which is not always feasible.但是,这需要管理员权限,这并不总是可行的。 For example, I'm thinking about ClickOnce deployments some time in the future - not sure how it will work with this.例如,我正在考虑未来某个时间的 ClickOnce 部署 - 不确定它将如何与此合作。 So I'm still wondering what should I do in order to get that dialog.所以我仍然想知道我应该怎么做才能获得那个对话框。


SOLUTION: thanks to @alexw answer below, I was able to get the dialog using this simple code:解决方案:感谢下面的@alexw 回答,我能够使用这个简单的代码获得对话框:

IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 12345);

TcpListener t = new TcpListener(ipLocalEndPoint);
t.Start();
t.Stop();

and more - it's NOT possible to get this popup for WCF service as documentation states (see at the bottom):以及更多 - 作为文档状态,无法为 WCF 服务获取此弹出窗口(请参阅底部):

Self-hosted HTTP addressing for WCF is not integrated into the Windows firewall. WCF 的自承载 HTTP 寻址未集成到 Windows 防火墙中。 An exception must be added to the firewall configuration to allow inbound connections using a particular URL.必须在防火墙配置中添加一个例外,以允许使用特定 URL 的入站连接。

在此处输入图片说明

I'm not sure what conditions need to be met to expose this dialog, I would assume an application that attempts to open a listening port on a vanilla Windows instance should always display this dialog.我不确定需要满足什么条件才能公开此对话框,我假设尝试在普通 Windows 实例上打开侦听端口的应用程序应始终显示此对话框。 Why don't you try adding your application to the 'authorized applications' list, or opening the port manually using the Windows Firewall COM interop (NetFwTypeLib)?为什么不尝试将您的应用程序添加到“授权应用程序”列表,或者使用 Windows 防火墙 COM 互操作 (NetFwTypeLib) 手动打开端口?

http://blogs.msdn.com/b/securitytools/archive/2009/08/21/automating-windows-firewall-settings-with-c.aspx http://blogs.msdn.com/b/securitytools/archive/2009/08/21/automating-windows-firewall-settings-with-c.aspx

Just guessing, but maybe you need to enable UAC Admin Rights for your app for this to pop up?只是猜测,但也许您需要为您的应用程序启用 UAC 管理员权限才能弹出?

Check out these blog posts on how to do that: http://victorhurdugaci.com/using-uac-with-c-part-2/查看这些关于如何做到这一点的博客文章: http : //victorhurdugaci.com/using-uac-with-c-part-2/

I think you have to add an Embeded Application manifest file to your application and set require administrator, so that you can excute a bach file in it which change firewall rules.我认为您必须向您的应用程序添加一个嵌入式应用程序清单文件并设置需要管理员,以便您可以在其中执行更改防火墙规则的 bach 文件。 here is an exemple how can open ports using a bach file这是一个如何使用 bach 文件打开端口的示例
Hope it helps希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM