Opc.Ua.Configuration.ConfigUtils.CheckFirewallAccess C# (CSharp) Method

CheckFirewallAccess() public static method

Checks if the firewall has been configured.
public static CheckFirewallAccess ( string executablePath, StringCollection baseAddresses ) : bool
executablePath string
baseAddresses StringCollection
return bool
        public static bool CheckFirewallAccess(string executablePath, StringCollection baseAddresses)
        {
            NetFwTypeLib.INetFwMgr fwm = GetNetFwMgr();

            bool found = false;

            foreach (NetFwTypeLib.INetFwAuthorizedApplication app in fwm.LocalPolicy.CurrentProfile.AuthorizedApplications)
            {
                if (app.ProcessImageFileName == executablePath)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                return false;
            }

            if (baseAddresses != null)
            {
                for (int ii = 0; ii < baseAddresses.Count; ii++)
                {
                    Uri url = Utils.ParseUri(baseAddresses[ii]);

                    // ignore invalid urls.
                    if (url == null || url.Port == -1)
                    {
                        continue;
                    }

                    foreach (NetFwTypeLib.INetFwOpenPort port in fwm.LocalPolicy.CurrentProfile.GloballyOpenPorts)
                    {
                        if (port.Port == url.Port)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return false;
                    }
                }
            }

            return true;
        }

Usage Example

コード例 #1
0
ファイル: FirewallAccessDlg.cs プロジェクト: fr830/OPCUA.NET
        private void ApplicationAccessGrantedCK_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (m_application != null)
                {
                    bool accessible = ConfigUtils.CheckFirewallAccess(m_application.ExecutablePath, null);

                    if (ApplicationAccessGrantedCK.Checked)
                    {
                        if (!accessible)
                        {
                            ConfigUtils.SetFirewallAccess(m_application.ExecutablePath, null);
                        }
                    }
                    else
                    {
                        if (accessible)
                        {
                            ConfigUtils.RemoveFirewallAccess(m_application.ExecutablePath, null);
                        }
                    }
                }

                PortsLV.Enabled   = ApplicationAccessGrantedCK.Checked;
                AddBTN.Enabled    = PortsLV.Enabled;
                RemoveBTN.Enabled = PortsLV.Enabled;
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
All Usage Examples Of Opc.Ua.Configuration.ConfigUtils::CheckFirewallAccess