I am using a code for forwarding a port. this code works fine on My Windows 7; but I can\'t use It on Windows XP.
Update 1 For Problem(2012-10-17 07:32:00Z)<
If you are getting an access violation, when you access the count property, this means which the IStaticPortMappingCollection interface returned by the IUPnPNAT.get_StaticPortMappingCollection method is nil, this can be caused by many reasons your device doesn't supports UPnP, The UPnP is not enabled on the device, The UPnP User Interface is not installed/active, and so on.
Anyway to prevent this kind of exceptions (the access violation) you must check the value returned by the property or method before to use it, in this case you can use the VarIsClear function like so :
try
Nat := CreateOleObject('HNetCfg.NATUPnP');
Ports := Nat.StaticPortMappingCollection;
if not VarIsClear(Ports) then
begin
//do something
ShowMessage(inttostr(Ports.count));
Ports.Add(Port, 'TCP', Port, LAN_IP, True, name);
end;
except on E:Exception do
ShowMessage('An Error occured with adding UPnP Ports. '+E.Message);
end;