问题
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.
回答1:
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.
回答2:
Windows Firewall has its own API for that purpose: Windows Firewall and Windows Firewall with Advanced Security. Look at the INetFwOpenPorts::Add() method.
回答3:
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.
回答4:
shoosh googled it for me and I came up with this, which works perfectly.
netsh firewall add portopening tcp #### "VNC"
Replacing #### with the port.
回答5:
See the source code of Windows firewall (posted on google groups, Win32)
来源:https://stackoverflow.com/questions/802687/what-api-calls-are-involved-in-opening-a-port-in-the-windows-firewall