【如何透过程序来控制 Windows XP防火墙的开关】Dim;objFW;As;Object;;;
Set;objFW;=;CreateObject("HNetCfg.FwMgr").LocalPolicy.CurrentProfile
With;objFW
.FirewallEnabled;=;True;";True;开启;,;False;关闭
.ExceptionsNotAllowed;=;True;";[;不允许例外;];选项;,;True;勾;,;反之则不勾
End;With
或
procedure;Set_WindowsXP_FireWall(Enable:;boolean);
//;需引用;winsvc,;shellapi
//;Set_WindowsXP_FireWall(false);;//;关闭Windows;Xp;防火
//
var
SCM,;hService:;LongWord;
sStatus:;TServiceStatus;
begin
if;Enable;=;false;then
begin
SCM;:=;OpenSCManager(nil,;nil,;SC_MANAGER_ALL_ACCESS);
hService;:=;OpenService(SCM,;PChar("SharedAccess"),;SERVICE_ALL_ACCESS);
ControlService(hService,;SERVICE_CONTROL_STOP,;sStatus);
CloseServiceHandle(hService);
end;
end;
设定Port;的部份,不过还没测试!不过我还是希望写成简单形式的函数库呼叫方式,大家一起测试吧!
出处:http://www-new.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22122056.html
Example;of;both;adding;and;removing;a;tcp;port;from;the;globaly;open;ports;list;(in;Windows;XP;firewall)
Regards,
Russell
//;Include;ActiveX;and;ComObj;in;uses;clause;(also;Variants;for;D6;and;up)
const
NET_FW_PROFILE_DOMAIN;;;;;;=;;0;
NET_FW_PROFILE_STANDARD;;;;=;;1;
const
NET_FW_IP_PROTOCOL_TCP;;;;;=;6;
NET_FW_IP_PROTOCOL_UDP;;;;;=;17;
const
NET_FW_SCOPE_ALL;;;=;;0;
const
NET_FW_IP_VERSION_ANY;;;;;;=;;2;
implementation
{$R;*.DFM}
procedure;TForm1.Button1Click(Sender:;TObject);
var;;ovMgr:;OleVariant;
ovProfile:;;;;;OleVariant;
ovPort:OleVariant;
begin
//;Create;manager;interface
ovMgr:=CreateOleObject("HNetCfg.FwMgr");
//;Resource;protection
try
//;Get;local;profile;interface
ovProfile:=ovMgr.LocalPolicy.CurrentProfile;
//;Resource;protection
try
//;Create;new;port;interface
ovPort:=CreateOleObject("HNetCfg.FwOpenPort");
try
//;Set;port;properties
ovPort.Port:=81;
ovPort.Name:="Whatever";
ovPort.Scope:=NET_FW_SCOPE_ALL;
ovPort.IpVersion:=NET_FW_IP_VERSION_ANY;
ovPort.Protocol:=NET_FW_IP_PROTOCOL_TCP;
ovPort.Enabled:=True;
//;Resource;protection
try
//;Add;to;globally;open;ports
ovProfile.GloballyOpenPorts.Add(ovPort);
////
//;....;do;whatever;....
////
finally
//;Remove;from;globally;open;ports
ovProfile.GloballyOpenPorts.Remove(81,;NET_FW_IP_PROTOCOL_TCP);
end;
finally
//;Release;interface
ovPort:=Unassigned;
end;
finally
//;Release;interface
ovProfile:=Unassigned;
end;
finally
//;Release;interface
ovMgr:=Unassigned;
end;
end;
推荐阅读
- 燕窝怎么形成的又是怎样提取的 燕窝是如何提取出来的
- N种方法教你如何进入有密码的WindowsXP系统
- 西窗烛如何添加诗单?添加诗单的步骤一览
- 如何辨别床单材质是不是纯棉
- 网易云音乐手机版主播电台是什么?如何收听主播电台?
- 触漫APP如何制作封面字体?制作封面字体的方法介绍
- 网易云音乐手机版定时播放功能如何使用?
- 音乐拍如何分享到朋友圈?音乐拍app分享到朋友圈的方法
- 美册APP如何去掉水印?去掉水印的方法说明
- 闲鱼鱼塘如何创建?闲鱼app创建鱼塘的方法