OK, I think that I have it figured out.
I had to create a type library file of the hnetcfg.dll. I did that when I first started but have learned a lot about the firewall objects since then. It didn't work then, but its working now. You can create your own file from Component|Import Component. And then follow the wizard.
The wrapping code uses exceptions which I normally don't like to do, but I don't know how to tell whether an Interface that is returning an Interface is actually returning data that I can work off of... So that would be an improvement if somebody can point me in the right direction.
And now to the code, with a thanks to Jim for his response.
constructor TFirewallUtility.Create;
begin
inherited Create;
CoInitialize(nil);
mxCurrentFirewallProfile := INetFwMgr(CreateOLEObject('HNetCfg.FwMgr')).LocalPolicy.CurrentProfile;
end;
function TFirewallUtility.IsPortInExceptionList(iPortNumber: integer): boolean;
begin
try
Result := mxCurrentFirewallProfile.GloballyOpenPorts.Item(iPortNumber, NET_FW_IP_PROTOCOL_TCP).Port = iPortNumber;
except
Result := False;
end;
end;
function TFirewallUtility.IsPortEnabled(iPortNumber: integer): boolean;
begin
try
Result := mxCurrentFirewallProfile.GloballyOpenPorts.Item(iPortNumber, NET_FW_IP_PROTOCOL_TCP).Enabled;
except
Result := False;
end;
end;
procedure TFirewallUtility.SetPortEnabled(iPortNumber: integer; sPortName: string; xProtocol: TFirewallPortProtocol);
begin
try
mxCurrentFirewallProfile.GloballyOpenPorts.Item(iPortNumber, CFirewallPortProtocalConsts[xProtocol]).Enabled := True;
except
HaltIf(True, 'xFirewallManager.TFirewallUtility.IsPortEnabled: Port not in exception list.');
end;
end;
procedure TFirewallUtility.AddPortToFirewall(sPortName: string; iPortNumber: Cardinal; xProtocol: TFirewallPortProtocol);
var
port: INetFwOpenPort;
begin
port := INetFwOpenPort(CreateOLEObject('HNetCfg.FWOpenPort'));
port.Name := sPortName;
port.Protocol := CFirewallPortProtocalConsts[xProtocol];
port.Port := iPortNumber;
port.Scope := NET_FW_SCOPE_ALL;
port.Enabled := true;
mxCurrentFirewallProfile.GloballyOpenPorts.Add(port);
end;