中甲

如何透过程序来控制 Windows XP防火墙的开关

2019-12-05 00:56:54来源:励志吧0次阅读

DimobjFWAsObject

SetobjFW=CreateObject("HNetCfg.FwMgr").LocalPolicy.CurrentProfile

WithobjFW

.FirewallEnabled=True"True开启,False关闭

.ExceptionsNotAllowed=True"[不允许例外]选项,True勾,反之则不勾

EndWith

procedureSet_WindowsXP_FireWall(Enable:boolean);

//需引用winsvc,shellapi

//Set_WindowsXP_FireWall(false);//关闭WindowsXp防火牆

//

var

SCM,hService:LongWord;

sStatus:TServiceStatus;

begin

ifEnable=falsethen

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

Exampleofbothaddingandremovingatcpportfromtheglobalyopenportslist(inWindowsXPfirewall)

Regards,

Russell

//IncludeActiveXandComObjinusesclause(alsoVariantsforD6andup)

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

procedureTForm1.Button1Click(Sender:TObject);

varovMgr:OleVariant;

ovProfile:OleVariant;

ovPort:OleVariant;

begin

//Createmanagerinterface

ovMgr:=CreateOleObject("HNetCfg.FwMgr");

//Resourceprotection

try

//Getlocalprofileinterface

ovProfile:=ovMgr.LocalPolicy.CurrentProfile;

//Resourceprotection

try

//Createnewportinterface

ovPort:=CreateOleObject("HNetCfg.FwOpenPort");

try

//Setportproperties

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;

//Resourceprotection

try

//Addtogloballyopenports

ovProfile.GloballyOpenPorts.Add(ovPort);

////

//....dowhatever....

////

finally

//Removefromgloballyopenports

ovProfile.GloballyOpenPorts.Remove(81,NET_FW_IP_PROTOCOL_TCP);

end;

finally

//Releaseinterface

ovPort:=Unassigned;

end;

finally

//Releaseinterface

ovProfile:=Unassigned;

end;

finally

//Releaseinterface

ovMgr:=Unassigned;

end;

end;

辽宁省肿瘤医院怎么样
送子鸟医院
上饶性病医院排名
乌鲁木齐去哪家医院治疗癫痫病
东莞牛皮癣医院哪家好
分享到: