Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

c# - Deploying NetFwTypeLib to manage the Windows Firewall

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.

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?


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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...