Exemple #1
0
        public FwErrorCode RemovePort(int nPortNumber, NET_FW_IP_PROTOCOL_ ipProtocol)
        {
            if (_mFirewallProfile == null)
            {
                return(FwErrorCode.FwErrInitialized);
            }

            bool        bEnablePort = false;
            FwErrorCode nError      = IsPortEnabled(nPortNumber, ipProtocol, ref bEnablePort);

            if (nError != FwErrorCode.FwNoerror)
            {
                return(nError);
            }

            // Only remove the port, if it is on the collection
            if (bEnablePort)
            {
                // Retrieve the collection of globally open ports
                INetFwOpenPorts fwOpenPorts = _mFirewallProfile.GloballyOpenPorts;
                if (fwOpenPorts == null)
                {
                    return(FwErrorCode.FwErrGlobalOpenPorts);
                }

                try
                {
                    fwOpenPorts.Remove(nPortNumber, ipProtocol);
                }
                catch
                {
                    return(FwErrorCode.FwErrRemoveFromCollection);
                }
            }

            return(FwErrorCode.FwNoerror);
        }
Exemple #2
0
        public FW_ERROR_CODE RemovePort(int nPortNumber, NET_FW_IP_PROTOCOL_ ipProtocol)
        {
            if (m_FirewallProfile == null)
            {
                return(FW_ERROR_CODE.FW_ERR_INITIALIZED);
            }

            bool          bEnablePort = false;
            FW_ERROR_CODE nError      = IsPortEnabled(nPortNumber, ipProtocol, ref bEnablePort);

            if (nError != FW_ERROR_CODE.FW_NOERROR)
            {
                return(nError);
            }

            // Only remove the port, if it is on the collection
            if (bEnablePort)
            {
                // Retrieve the collection of globally open ports
                INetFwOpenPorts FWOpenPorts = m_FirewallProfile.GloballyOpenPorts;
                if (FWOpenPorts == null)
                {
                    return(FW_ERROR_CODE.FW_ERR_GLOBAL_OPEN_PORTS);
                }

                try
                {
                    FWOpenPorts.Remove(nPortNumber, ipProtocol);
                }
                catch
                {
                    return(FW_ERROR_CODE.FW_ERR_REMOVE_FROM_COLLECTION);
                }
            }

            return(FW_ERROR_CODE.FW_NOERROR);
        }