When no firewall is involved, a port is open when a service/program is listening on that port. If you want to open a port then you need to start the program/service that listens on that port.
Once a program/service is listening on a port, you can close the port with the help of a firewall.
The Windows’ firewall closes ports by default, but you can add the appropriate exceptions to open them. These exceptions can be added in the GUI, or using the <a href=”http://msdn.microsoft.com/en-us/library/aa364679(VS.85).aspx”>Windows Firewall API</a> from a program or script.
While I agree that it takes a program to open a “listening” port, a firewall does not necessarily “close” a port. A firewall <b>filters</b> traffic to/from a particular port to ensure it meets the defined rules for that application/service/user, etc.
Ports are typically opened on a machine when an application is started that sends traffic to a destination host/service – this creates a SOURCE port. When an application is started on a machine that provides services to other systems – that creates a DESTINATION port. The directions will be changed when traffic goes between the client and the server. In some cases the source port becomes the destination port when traffic is returned from the hosting system/service.
Can you tell us more about what you are wanting to do to open/close ports on a Windows system?