How to programmatically add an application or port to Windows Firewall on Windows XP?
Scripting the Windows Firewall is possible, see Scripting the Windows Firewall
And code examples for example here