falahati / WindowsFirewallHelper

A class library to manage the Windows Firewall as well as adding your program to the Windows Firewall Exception list.
MIT License
274 stars 72 forks source link

Dialog box "Windows Security Alert". Project selects checkbox "Private networks, such as my home or work network" itself #49

Closed bob-byte closed 2 years ago

bob-byte commented 2 years ago

User will have this dialog if my project is run for the first time: image How to make my project communicating in private networks without the user's request? I only have tried to code as in an example: var rule = FirewallManager.Instance.CreateApplicationRule( @"MyApp Rule", FirewallAction.Allow, @"C:\MyApp.exe" ); rule.Direction = FirewallDirection.Outbound; FirewallManager.Instance.Rules.Add(rule); But I get an exception UnauthorizedAccessException in the last row: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at WindowsFirewallHelper.COMInterop.INetFwRules.Add(INetFwRule rule) at WindowsFirewallHelper.Collections.FirewallWASRulesCollection'1.InternalAdd(INetFwRule native) at WindowsFirewallHelper.InternalHelpers.Collections.ComCollectionBase'4.Add(TManaged item)

falahati commented 2 years ago

you need elevation to be able to add firewall rules