views:

177

answers:

5

I have a batch file that installs WinVNC in about 1 second and starts up the service. However, I still have to manually go into the Windows Firewall and open a port to allow connections. How can I do that programmatically?

If I could do it from inside the batch file, that would be ideal, but I'm ok writing an EXE if that's necessary.

+2  A: 

Let me google that for you:
http://www.windowsecurity.com/articles/Customizing-Windows-Firewall.html

This page includes a multitude of ways to customize the firewall, among those the use of netsh.exe that seem to give command line access to windows firewall.

shoosh
+1  A: 

Here is a good resource that I have used multiple times in the past. I know it's the typical 'point to the RTFM site', but really, it is a good resource and I have used it successfully.

http://msdn.microsoft.com/en-us/library/aa366415(VS.85).aspx

Good luck.

Andrew Sledge
A: 

shoosh googled it for me and I came up with this, which works perfectly.

netsh firewall add portopening tcp #### "VNC"

Replacing #### with the port.

JosephStyons
A: 

See the source code of Windows firewall (posted on google groups, Win32)

<sarcasm>link please</sarcasm>
JosephStyons
+2  A: 

Windows Firewall has its own API for that purpose: Windows Firewall and Windows Firewall with Advanced Security. Look at the INetFwOpenPorts::Add() method.

Remy Lebeau - TeamB