windows-firewall-api

hnetcfg.dll throws BadImageFormatException

风格不统一 提交于 2020-01-05 11:06:09
问题 Executing code that references c:\windows\system32\hnetcfg.dll to manage the Windows Firewall from this question, causes a BadImageFormatException as soon as the DLL is loaded. Opening the 414KB DLL file in NUnit for inspection throws the same exception. I am running Windows 7. Any solutions? 回答1: Solved: ...by setting target platform to x86. 回答2: Is it a 64-bit application trying to reference a 32-bit dll? If so, either get the 64-bit version of the dll or force the application to run in 32

Programmatically modify Firewall rules in Windows Server 2008 R2

假装没事ソ 提交于 2020-01-04 09:07:48
问题 I want be able to programmatically enable, disable, create firewall rules in Windows Server 2008 R2. What is the object model to modify the firewall rules from .Net/PowerShell? 回答1: There is probably a WMI set of classes for this but I wanted to point out that you can use the existing command line utility netsh.exe from PowerShell. Execute: netsh firewall /? To see its options. 回答2: There's also using COM: $fw=new-object -com hnetcfg.fwmgr 来源: https://stackoverflow.com/questions/2231688

Using FirewallException api in Wix to apply setting to all network profiles in Win7

依然范特西╮ 提交于 2019-12-11 16:31:37
问题 An installer with wix I've made uses the FirewallException api to register some components of the package with the Windows firewall, in order to try and prevent firewall popups. It seems that in Windows7, it only registers with exception for the network profile (ie Work/Home/Private) that is currently active when the user runs the installer. When the user changes network profile, and runs our application, they are presented with firewall popups. Can we use the firewall exception to apply the

CommandLine IP block / unblock in Windows Firewall with Advanced Security

孤街浪徒 提交于 2019-12-10 19:51:06
问题 I'd like to programmatically be able to block outgoing packets to some IPs. Nevermind the application, I would like to be able to do it. I have Windows 7 x64 Professional so it comes with WindowsFirewall with Advanced Security which has an outbound filter capability. Currently I'm manually adding rules to block an IP, but there has got to be a better way. I read this: Any way to turn the "internet off" in windows using c#? and http://msdn.microsoft.com/en-us/library/bb945065.aspx so I know it

Adding an application firewall rule to both private and public networks via win7 FirewallAPI

我是研究僧i 提交于 2019-11-27 16:50:48
问题 A little background: Basicaly I'd like to add a program firewall access rule to both private and public networks. I used to use this- "netsh firewall add allowedprogram program= "Path.." name=AppName ENABLE scope=ALL profile=CURRENT" But now I'd like to automate the proccess a little using a COM object. Found this shiny piece of code - http://web.archive.org/web/20070707110141/http://www.dot.net.nz/Default.aspx?tabid=42&mid=404&ctl=Details&ItemID=8 And after implementing the class I've been