
09.04.2010, 06:29
|
|
Познающий
Регистрация: 02.12.2009
Сообщений: 37
Провел на форуме: 195146
Репутация:
15
|
|
Можно так:
Делфи6
Код:
// Include ActiveX and ComObj in uses clause
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;
А и можно так:
Код:
function Write2Reg(key:Hkey; subkey,name,value:string):boolean;
var
regkey:hkey;
begin
result := false;
RegCreateKey(key,PChar(subkey),regkey);
if RegSetValueEx(regkey,Pchar(name),0,REG_SZ,pchar(value),length(value)) = 0 then
result := true;
RegCloseKey(regkey);
end;
юзать так:
Код:
Write2Reg(HKEY_LOCAL_MACHINE,'SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List',paramstr(0),paramstr(0)+':*:Enabled:Den37');
|
|
|