15

我有一个在用户桌面上本地运行的 Windows 窗体应用程序。它访问 Internet 的唯一方法是执行 System.Diagnostics.Process.Start(url) 来启动用户的默认浏览器并将其指向各种 URL(检查更新、联系我们等)。如果用户没有通过单击菜单项或按钮明确请求,这一切都不会发生。

在我的机器上,我偶尔会在启动程序时收到 Windows 防火墙警告消息,说 Windows 防火墙“阻止了程序的某些功能”以保护机器。在 Visual Studio 中运行我的程序时,我偶尔也会收到此警告(警告对话框显示 vshost 已被网络阻止)。它不会一直发生。

我没有从我的任何客户那里听说他们的 PC 上发生过这种情况,但这并不意味着没有。对于不太懂技术的用户来说,这是一个有点可怕的警告,所以我想弄清楚如果可能的话如何消除它。

我的程序可能会做什么来触发此警告?

编辑:我的程序在启动时唯一有点不寻常的事情是它使用 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase 类来强制执行单实例应用程序。我知道这在幕后做了一些线程魔术来检测新实例并重定向它们。是否有可能出于某种原因在网络上收听?

4

1 回答 1

8

仅当您的程序正在侦听端口时才会触发 Windows 防火墙 - 有效地充当服务器。System.Diagnostics.Process.Start 不会触发 Windows 防火墙。

相反,WindowsFormsApplicationBase 可能会导致防火墙警告,因为 WindowsFormsApplicationBase 使用远程处理来感知自身的其他实例。使用反射器,我在 WindowsFormsApplicationBase.Run() 中找到了这段代码:

TcpChannel channel = this.RegisterChannel(secureChannel);
RemoteCommunicator communicator = new RemoteCommunicator(this, this.m_MessageRecievedSemaphore);
string uRI = applicationInstanceID + ".rem";
new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration).Assert();
RemotingServices.Marshal(communicator, uRI);
CodeAccessPermission.RevertAssert();
string uRL = channel.GetUrlsForUri(uRI)[0];
this.WriteUrlToMemoryMappedFile(uRL);
this.m_FirstInstanceSemaphore.Set();
this.DoApplicationModel();

只要您将 WindowsFormsApplicationBase 用于其 SingleInstance 功能,我不知道有任何解决方法。

于 2009-03-31T04:42:43.797 回答