如何以编程方式将应用程序或端口添加到Windows XP上的Windows防火墙?XP的Windows防火墙规则
13
A
回答
17
尝试从我们的开源SQlite3UI.pas部提取出验证码:
function GetXPFirewall(var fwMgr, profile: OleVariant): boolean;
begin
Result := (Win32Platform=VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion>5) or ((Win32MajorVersion=5) and (Win32MinorVersion>0));
if result then // need Windows XP at least
try
fwMgr := CreateOleObject('HNetCfg.FwMgr');
profile := fwMgr.LocalPolicy.CurrentProfile;
except
on E: Exception do
result := false;
end;
end;
const
NET_FW_PROFILE_DOMAIN = 0;
NET_FW_PROFILE_STANDARD = 1;
NET_FW_IP_VERSION_ANY = 2;
NET_FW_IP_PROTOCOL_UDP = 17;
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_SCOPE_ALL = 0;
NET_FW_SCOPE_LOCAL_SUBNET = 1;
procedure AddApplicationToXPFirewall(const EntryName, ApplicationPathAndExe: string);
var fwMgr, profile, app: OleVariant;
begin
if GetXPFirewall(fwMgr,profile) then
try
if profile.FirewallEnabled then begin
app := CreateOLEObject('HNetCfg.FwAuthorizedApplication');
try
app.ProcessImageFileName := ApplicationPathAndExe;
app.Name := EntryName;
app.Scope := NET_FW_SCOPE_ALL;
app.IpVersion := NET_FW_IP_VERSION_ANY;
app.Enabled :=true;
profile.AuthorizedApplications.Add(app);
finally
app := varNull;
end;
end;
finally
profile := varNull;
fwMgr := varNull;
end;
end;
procedure AddPortToXPFirewall(const EntryName: string; PortNumber: cardinal);
var fwMgr, profile, port: OleVariant;
begin
if GetXPFirewall(fwMgr,profile) then
try
if profile.FirewallEnabled then begin
port := CreateOLEObject('HNetCfg.FWOpenPort');
port.Name := EntryName;
port.Protocol := NET_FW_IP_PROTOCOL_TCP;
port.Port := PortNumber;
port.Scope := NET_FW_SCOPE_ALL;
port.Enabled := true;
profile.GloballyOpenPorts.Add(port);
end;
finally
port := varNull;
profile := varNull;
fwMgr := varNull;
end;
end;
它可以让你将应用程序或端口添加到XP防火墙。 应该从Delphi 6一直工作到XE。
+1
我已经更新了单元的源代码,可以在XP,Vista和Seven上运行,可以用于应用程序,也可以用于端口。请参阅http://synopse.info/forum/viewtopic.php?pid=4652#p4652 – 2012-07-11 06:51:16
6
脚本编写Windows防火墙是可能的,例如见Scripting the Windows Firewall
和代码示例here
相关问题
- 1. Linux iptabxes防火墙规则
- 2. 解析Python中的防火墙规则
- 3. 无法添加防火墙规则
- 4. SQL Azure 0.0.0.0防火墙规则
- 5. 优化防火墙规则处理
- 6. 如何检查Windows防火墙中的规则?
- 7. 是否有更改Windows Server 2008上防火墙规则的API?
- 8. 使用Delphi删除Windows防火墙规则(例外)
- 9. 在Windows Phone 8.1上添加防火墙规则
- 10. Windows防火墙入站规则和环境PATH变量
- 11. 删除防火墙规则在Windows 7上使用Powershell
- 12. 从Java Web Start(JNLP)修改Windows防火墙规则
- 13. 将iptables规则转换为防火墙cmd规则
- 14. 控制Windows防火墙在C#中对Windows 7和XP SP3
- 15. 这是Windows XP防火墙的错误吗?
- 16. Windows防火墙编程
- 17. 为Windows编程防火墙
- 18. C#HttpListener和Windows防火墙
- 19. 自动化Windows防火墙
- 20. NetTcpBinding和Windows 7防火墙
- 21. 在Windows Azure上重新启用远程桌面Windows防火墙规则
- 22. Windows防火墙的Windows Server 2012 R2
- 23. PowerShell的避免增加重复的防火墙规则的Windows 7
- 24. 更改Windows防火墙远程地址的脚本,排除localsubnets的规则
- 25. 如何使用Powershell确定Windows防火墙规则的程序路径Get-NetFirewallRule
- 26. 以编程方式修改Windows Server 2008 R2中的防火墙规则
- 27. Symfony2的防火墙规则无法正常运行
- 28. 指定的值无效。使用C#添加防火墙规则
- 29. 防火墙规则C的正确设置#
- 30. 让Azure的防火墙规则自动失效
可能重复的[编程向Windows vista防火墙添加例外](http://stackoverflow.com/questions/1409896/programatically-add-exception-to-windows-vista-firewall) – 2011-04-20 13:34:38
可能的重复[Add to防火墙例外列表](http://stackoverflow.com/questions/2384718/add-to-firewall-exception-list) – 2011-04-20 14:11:47
这个答案只适用于XP。因为OP接受了这个及其有用的信息,所以不是一个骗局,因为重复的作品只在win7和vista中。 – 2012-07-07 22:09:31