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

Meaning of FirewallManager.IsServiceRunning and FirewallManager.Version #55

Open Wenski opened 2 years ago

Wenski commented 2 years ago

Hi,

at first a big thanks for wrapping nicer code around the windows firewall! I tried to use WindowsFirewallHelper to add a rule at program start to my computers firewall. After a while and with your example code I found that IsServiceRunning returns false and Version returns None. I tried on two machines running Windows 11 with same results. On both machines "Domain Networks" is disabled, private and public networks are enabled. Do the results refer to the disabled "Domain Networks" firewall or does it mean something different?

Thanks, Christian

falahati commented 2 years ago

Version shows what version of Windows Firewall is detected on the system. IsServiceRunning tries to check and see if the Windows Firewall Service is running.

None of these should break your code. Can you post the code used to create the rule here?

Also, on what platform are you using this library? There might be some limitations with new UI frameworks.

I did not have the time or courage to try Win11 yet, probably late 2022 or next year when it is more mature; so, unfortunately, I can not provide specific support for Win11 but I try to point you in the right direction if I suspect something.

falahati commented 2 years ago

make sure you are running the app as admin btw

Wenski commented 2 years ago

Although I am pretty sure it is running with elevated right I am going to perform a test tomorrow again. It is a net6.0 console project running on Windows 10, Windows 11 is not a topic yet (and maybe never). I will post code tomorrow. Thanks for your quick response.

Wenski commented 2 years ago

So after comparing with your example code and playing around I found that my net6.0 publish single configuration is the culprit. I was able to reproduce the problem with WindowsFirewallHelper.NetCoreSample by changing the csproj as below. You might have to do a clean build. It seems like this is an issue in combination with net6.0. Changing TargetFramework to net5.0 works fine and that is what I am going to do.

cpsroj content:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
    <PropertyGroup>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
        <PublishTrimmed>true</PublishTrimmed>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BasicConsoleUtilities" Version="1.0.0.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\WindowsFirewallHelper\WindowsFirewallHelper.csproj" />
  </ItemGroup>

</Project> 
falahati commented 2 years ago

so this problem is with our latest release for .net6 probably or with the prior version; can you check the v2.2.0.86 and v2.1.4.81 separately? the only difference between the two is the net6 separate builds in v2.2.0.86. v2.1.4.81 however uses netstandard for forward compatibility.

Windows 11 is not a topic yet

I misunderstood the initial comment then. thought it is a win11 issue.

bmueller84 commented 2 years ago

Could this one be related to a general trimming incompatibilities?

bmueller84 commented 2 years ago

Looked a little more into this, and it appears that the problem really is related to the combination of trimming and COM interop. I was able to get it to work by adding <BuiltInComInteropSupport>true</BuiltInComInteropSupport> to csproj (see here) but the option is marked as risky.

simonmurdock commented 2 years ago

Bumped into an issue today where module trimming / single assembly was also to blame. worked fine once I put it back to a normal self-contained build.