I am trying to iterate within INetFwServices elements in Windows 10. However when I access to item Service Name: "Remote Desktop" Type: NET_FW_SERVICE_REMOTE_DESKTOP the application throws an exception Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).

The firewall.LocalPolicy.CurrentProfile.Services collection returns 3 items: 1. File and Printer Sharing 2. Network Discovery 3. Remote Desktop

When I read the third item "Remote Desktop" to get its GloballyOpenPorts occurred the error.

In Windows 7 this type NET_FW_SERVICE_REMOTE_DESKTOP works correctly but in Windows 10 fails. How can I read the GloballyOpenPorts of Service Name: "Remote Desktop" in Windows 10?

progID = Type.GetTypeFromProgID("HNetCfg.FwMgr");
            firewall = Activator.CreateInstance(progID) as INetFwMgr;
            ports = firewall.LocalPolicy.CurrentProfile.GloballyOpenPorts;

            Debug.WriteLine("Count Services: " +  firewall.LocalPolicy.CurrentProfile.Services.Count);

            foreach (INetFwService service in firewall.LocalPolicy.CurrentProfile.Services)
            {
                Debug.WriteLine("Service: " + service.Name);

                var port = service.GloballyOpenPorts;
            }

StackTrace: at NetFwTypeLib.INetFwService.get_GloballyOpenPorts() at FirewallCustomTest.Firewall.isPortFound(Int32 portNumber) in c:\Users\Smartmatic\Documents\Visual Studio 2012\Projects\FirewallCustomTest\FirewallCustomTest\Firewall.cs:line 178

0

There are 0 answers