c# - 部署 NetFwTypeLib 以管理 Windows 防火墙

标签 c# deployment assemblies filenotfoundexception windows-firewall

我的 Windows 服务需要从 Windows 防火墙中创建/删除某些规则。为此,我与 NetFwTypeLib 进行交互在<windows>\system32\hnetcfg.dll通过 COM。 在我的 64 位 Windows 7 机器上运行良好,但在另一台 64 位 Windows 7 机器上测试会抛出以下错误:

Service cannot be started. System.IO.FileNotFoundException:
Could not load file or assembly 'Interop.NetFwTypeLib, 
   Version=1.0.0.0, Culture=neutral,
   PublicKeyToken=null' or one of its dependencies.
   The system cannot find the file specified.

我有一种感觉,如果我将程序集嵌入并安装到我的应用程序中,我会遇到不同版本的 Windows 以及 32 位和 64 位之间的问题。

我该如何解决这个缺少的程序集部署问题?


编辑:这似乎是一个 VS2010 issue对于除 4.0 以外的任何目标框架。有人对此有解决办法吗?

最佳答案

NetFwTypeLib 对象不驻留在 Windows 7 Ultimate 上的 hnetcfg.dll 库中。相反,它位于 %system32%\FirewallAPI.dll 的 FirewallAPI.dll 中(例如 c:\windows\system32\FirewallAPI.dll)。

使用 NetFwTypeLib;// 添加引用 %SystemRoot%\System32\FirewallAPI.dll

关于c# - 部署 NetFwTypeLib 以管理 Windows 防火墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4296240/

相关文章:

c# - 如何获取我在 Unity (C#) 中连接的 wifi 的 BSSID?

c# - 使用 WebHttpBinding 为 WCF 服务定义 'app.config'

.net - 在 .NET 中,有没有办法启用 Assembly.Load 跟踪?

python - 在 aws 上运行 django 项目的最佳方式是什么?

c# - “您必须添加对 Microsoft.Practices.EnterpriseLibrary.Common 的引用”,即使程序集位于 GAC 中

.net - 考虑在没有 app.config 映射的情况下对程序集进行 app.config 重新映射

c# - 如何使用 LINQ 对未知数量数组的元素求和?

c# - CollectionView SelectedItem 在 Xamarin Forms 中未突出显示

javascript - 如何从 Create React App/build 文件夹制作 npm 包?

deployment - 最佳实践 : Erlang Application Deploy on windows