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

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

问题描述

我的Windows服务需要从Windows防火墙创建/删除某些规则。为此,我通过COM与< windows> \system32\hnetcfg.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>\system32\hnetcfg.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:\windows\system32\FirewallAPI.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:\windows\system32\FirewallAPI.dll).

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

using NetFwTypeLib; // Add reference %SystemRoot%\System32\FirewallAPI.dll

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

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