日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

如何透過程序來(lái)控制 Windows XP防火墻的開關(guān)

【如何透過程序來(lái)控制 Windows XP防火墻的開關(guān)】Dim;objFW;As;Object;;;

Set;objFW;=;CreateObject("HNetCfg.FwMgr").LocalPolicy.CurrentProfile
With;objFW
.FirewallEnabled;=;True;";True;開啟;,;False;關(guān)閉
.ExceptionsNotAllowed;=;True;";[;不允許例外;];選項(xiàng);,;True;勾;,;反之則不勾
End;With




procedure;Set_WindowsXP_FireWall(Enable:;boolean);
//;需引用;winsvc,;shellapi
//;Set_WindowsXP_FireWall(false);;//;關(guān)閉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;

設(shè)定Port;的部份,不過還沒測(cè)試!不過我還是希望寫成簡(jiǎn)單形式的函數(shù)庫(kù)呼叫方式,大家一起測(cè)試吧!

出處: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;

    推薦閱讀