Managing Windows firewall with C#(using FirewallAPI)

0

I want to manage windows firewall using windows API with .NET C# on dotnet 3.5.

This is what I did.

Type netFwPolicy2Type = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");

var manage =  (INetFwPolicy2)Activator.CreateInstance(netFwPolicy2Type);

My application builds successfully in Visual Studio 2017, but when I run it I get the following error:

The program '[3240] firewallmanage.exe' has exited with code -532459699 (0xe0434f4d).

And when I compile in .net 4.5, it works perfectly. Please tell me what went wrong.

c#
firewall
asked on Stack Overflow Apr 3, 2018 by Rajat Kinkhabwala • edited Apr 3, 2018 by Fizz

1 Answer

0

I built the program in lower version of .net version and copied the reference DLL(Interop.NetFwTypeLib.dll) from build.This dll was causing the issue because of framework dependency but It started working fine after replacing dll

answered on Stack Overflow Apr 4, 2018 by Rajat Kinkhabwala

User contributions licensed under CC BY-SA 3.0