在 Windows 防火墙中打开端口涉及哪些 API 调用?
我有一个批处理文件,可以在大约 1 秒内安装 WinVNC 并启动服务。 但是,我仍然需要手动进入 Windows 防火墙并打开端口以允许连接。 我怎样才能以编程方式做到这一点?
如果我可以从批处理文件中执行此操作,那将是理想的,但如果有必要,我可以编写一个 EXE。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Windows 防火墙有自己的 API 用于此目的:Windows 防火墙和具有高级安全性的 Windows 防火墙。 查看 INetFwOpenPorts::Add() 方法。
Windows Firewall has its own API for that purpose: Windows Firewall and Windows Firewall with Advanced Security. Look at the INetFwOpenPorts::Add() method.
让我Google 为您提供:
http://www.windowsecurity.com/articles/Customizing-Windows-Firewall。 html
此页面包含多种自定义防火墙的方法,其中使用
netsh.exe
似乎可以通过命令行访问 Windows 防火墙。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.这是我过去多次使用过的好资源。 我知道这是典型的“指向 RTFM 站点”,但实际上,它是一个很好的资源,而且我已经成功地使用了它。
http://msdn.microsoft.com/en-us /library/aa366415(VS.85).aspx
祝你好运。
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.
shoosh 帮我在谷歌上搜索了一下,我想出了这个,效果非常好。
将 #### 替换为端口。
shoosh googled it for me and I came up with this, which works perfectly.
Replacing #### with the port.
查看Windows防火墙的源代码(发布在google groups,Win32上)
See the source code of Windows firewall (posted on google groups, Win32)