3

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

  • 1
    What's the question? – Demitrian Jan 19 '16 at 21:05
  • 2
    How can I read the GloballyOpenPorts of Service Name: "Remote Desktop" in Windows 10? – juancalbarran Jan 19 '16 at 21:18
  • The [MSDN documentation for INetFwService::GloballyOpenPorts](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365508(v=vs.85).aspx) says: "The Windows Firewall API is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. For Windows Vista and later, use of the [Windows Firewall with Advanced Security API](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366458(v=vs.85).aspx) is recommended." I would try that if I were you.. – yms Jan 20 '16 at 14:59

0 Answers0