|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionDuring the installation of my application, I need to add it to the Windows firewall as an allowed application and open 2 ports for another application. So this code will function as a custom action during the install to open the firewall on install and close it on uninstall. In trying to keep things as simple as possible; the following C# class library will be called from setup - openFirewall() and closeFirewall(). First, I generated FWSetupAction project as a C# class library. After that use the properties page to switch the output type to a console application to step through it with the debugger. When it's operational, switch back to class library for integration with MSI setup logic and incorporate it as a custom action. After the initial project creation, rename Class1.cs to Firewall.cs in the Solution navigator. If you're writing code anew, add the NetFwTypeLib reference first to allow intellisense to help you recognize the terms you'll be coding. This reference will be required for correct compilation, so whether you put it in before coding or after doesn't matter but it will be needed. To add the reference, right click on References and select browse. Browse to %windir%\system32\hnetcfg.dll and select it - the NetFwTypeLib will be created. Edit the Firewall.cs class to have the following code
Once compiled, you're ready to test. Set a break point on each of the firewall entry methods - openFirewall() and closeFirewall() and step through the program. Use a DOS box to verify the operations. The netsh firewall command will verify the operation of the code: netsh fire show allowed - shows the programs that are allowed netsh fire show port - shows the ports that are open Thanks to Moah, Windows XP SP2 Firewall Controller, http://www.codeproject.com/w2k/WinXPSP2Firewall.asp Thanks too to Dan Agonistes, Windows XP Service Pack 2 and the Windows Firewall, http://danagonistes.blogspot.com/2004/06/windows-xp-service-pack-2-and-windows.html
|
||||||||||||||||||||||