Another way to do this is to use the netsh command. You would launch it as a process using Process.Start. This works on XP and Windows 7 (I assume Vista also because it works on 7).
For example, if you wanted to open UDP port 20502, the netsh command would be:
netsh firewall add portopening UDP 20502 UserFriendlyName ENABLE ALL
And, if you wanted to close the port:
netsh firewall delete portopening UDP 20502 ALL
If you want to add a program exception to the firewall:
netsh firewall add allowedprogram "c:\program files\your folder\your.exe" UserFriendlyName
If you want to remove a program exception from the firewall:
netsh firewall delete allowedprogram "c:\program files\your folder\your.exe"