webowner47
Programmer
This the code i found in Stack Overflow but in Delphi not C++:
So, i tried my best to translate that in C++:
But, I get error like this:
Please i really need some help
Code:
uses
SysUtils,
ActiveX,
ComObj,
Variants;
procedure AddExceptionToFirewall(Const Caption, Executable: String;Port : Word);
const
NET_FW_PROFILE2_DOMAIN = 1;
NET_FW_PROFILE2_PRIVATE = 2;
NET_FW_PROFILE2_PUBLIC = 4;
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_ACTION_ALLOW = 1;
NET_FW_RULE_DIR_IN = 1;
NET_FW_RULE_DIR_OUT = 2;
var
fwPolicy2 : OleVariant;
RulesObject : OleVariant;
Profile : Integer;
NewRule : OleVariant;
begin
Profile := NET_FW_PROFILE2_PRIVATE OR NET_FW_PROFILE2_PUBLIC;
fwPolicy2 := CreateOleObject('HNetCfg.FwPolicy2');
RulesObject := fwPolicy2.Rules;
NewRule := CreateOleObject('HNetCfg.FWRule');
NewRule.Name := Caption;
NewRule.Description := Caption;
NewRule.Applicationname := Executable;
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP;
NewRule.LocalPorts := Port;
NewRule.Direction := NET_FW_RULE_DIR_OUT;
NewRule.Enabled := TRUE;
NewRule.Grouping := 'My Group';
NewRule.Profiles := Profile;
NewRule.Action := NET_FW_ACTION_ALLOW;
RulesObject.Add(NewRule);
end;
So, i tried my best to translate that in C++:
Code:
const NET_FW_PROFILE2_DOMAIN = 1;
const NET_FW_PROFILE2_PRIVATE = 2;
const NET_FW_PROFILE2_PUBLIC = 4;
const NET_FW_IP_PROTOCOL_TCP = 6;
const NET_FW_IP_PROTOCOL_UDP = 17;
const NET_FW_ACTION_ALLOW = 1;
const NET_FW_RULE_DIR_IN = 1;
const NET_FW_RULE_DIR_OUT = 2;
Variant fwPolicy2, RulesObject, NewRule;
DWORD Profile;
Profile = NET_FW_PROFILE2_PRIVATE | NET_FW_PROFILE2_PUBLIC;
fwPolicy2 = CreateOleObject("HNetCfg.FwPolicy2");
RulesObject = fwPolicy2.OlePropertyGet("Rules");
NewRule = CreateOleObject("HNetCfg.FWRule");
NewRule.OlePropertyGet("Name") = "Text Firewall";
NewRule.OlePropertyGet("Description") = "Text Firewall";
NewRule.OlePropertyGet("Applicationname") = "System_RCC.exe";
NewRule.OlePropertyGet("Protocol") = NET_FW_IP_PROTOCOL_TCP;
NewRule.OlePropertyGet("LocalPorts") = Edit1->Text;
NewRule.OlePropertyGet("Direction") = NET_FW_RULE_DIR_OUT;
NewRule.OlePropertyGet("Enabled") = true;
NewRule.OlePropertyGet("Grouping") = "";
NewRule.OlePropertyGet("Profiles") = Profile;
NewRule.OlePropertyGet("Action") = NET_FW_ACTION_ALLOW;
RulesObject.Add(NewRule);
But, I get error like this:
Compile Error said:add' is not a member of 'variant' borland c++ builder
Please i really need some help