部署 NetFwTypeLib 来管理 Windows 防火墙 [英] Deploying NetFwTypeLib to manage the Windows Firewall

查看:24
本文介绍了部署 NetFwTypeLib 来管理 Windows 防火墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 服务需要从 Windows 防火墙创建/删除某些规则.为此,我通过 COM 与 system32hnetcfg.dll 中的 NetFwTypeLib 接口.它在我的 64 位 Windows 7 机器上运行良好,但在另一台 64 位 Windows 7 机器上测试会引发以下错误:

My Windows service needs to create/remove certain rules from the Windows firewall. For this I interface with NetFwTypeLib in <windows>system32hnetcfg.dll via COM. It works great on my 64-bit Windows 7 machine, but testing on another 64-bit Windows 7 machine throws the following error:

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 位之间的问题.

I have a feeling that if I embed and install the assembly with my application, I would have problems with different versions of Windows and between 32-bit and 64-bit.

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

How do I solve this missing assembly deployment issue?

这似乎是一个VS2010 问题 适用于除 4.0 以外的任何目标框架.有没有人解决这个问题?

This seems to be a VS2010 issue for any target framework except 4.0. Does anyone have a fix for this?

推荐答案

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

NetFwTypeLib object doesn't reside in hnetcfg.dll library on Windows 7 Ultimate. Rather, it resides in FirewallAPI.dll at %system32%FirewallAPI.dll (eg c:windowssystem32FirewallAPI.dll).

使用 NetFwTypeLib;//添加参考%SystemRoot%System32FirewallAPI.dll

using NetFwTypeLib; // Add reference %SystemRoot%System32FirewallAPI.dll

这篇关于部署 NetFwTypeLib 来管理 Windows 防火墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆