It really depends on what kind of firewall you have. I found this great article
"Programmatically Controlling a UPnP-Capable Firewall"[
^] that shows a way to do what you want. It has a couple of vb scripts utilizing CreateObject, so if you have a firewall that is UPnP enabled the examples should also be translateable to C#.
I hope this helps you gather some ideas.
Cheers and happy coding!
Modification:
Another great starter is this CP article:
Programmatically disable/enable Windows firewall[
^]. The interesting bit is right on top of said article:
"Click Browse tab -> Add C:\windows\system32\Hnetcfg.dll & Click COM tab -> Add NetFwTypeLib."
This allows you to gain access to these DLLs from your C# project. The CP article is in VB, but that should be a reasonable task for an accomplished programmer to port to C#.