简体   繁体   English

以编程方式将应用程序添加到所有配置文件Windows防火墙(Vista +)

[英]Programmatically add an application to all profile Windows Firewall (Vista+)

I have searched around and there are similar questions on SO, however, no one talks about how to add exception to "All Profile" (windows 7, AKA "Any Profile" on Vista/Windows Server 2008). 我已经搜索过,并且在SO上有类似的问题,但是,没有人谈论如何在“All Profile”(Windows 7,AKA“任何配置文件”在Vista / Windows Server 2008上)添加例外。 Examples on internet talk about add to current profile only. 互联网上的例子谈论仅添加到当前配置文件。

The reason for this is I have a problem with one of my virtual machine: windows 2008 x86, current firewall profile is Domain, and my application is added to Exception list of Domain. 原因是我的虚拟机有一个问题:windows 2008 x86,当前的防火墙配置文件是Domain,我的应用程序被添加到Domain的Exception列表中。 (Firewall setting is as default: block any inbound calls that are not in exception list.) However, inbound calls are still blocked unless : 1. turn off firewall on that this virtual machine. (防火墙设置为默认设置:阻止任何不在例外列表中的入站呼叫。)但是,入站呼叫仍会被阻止,除非:1。关闭此虚拟机上的防火墙。 2. manually change rule profile of my application to "any" 2.手动将我的应用程序的规则配置文件更改为“任何”

It is very confusing as I thought only active profile should be "active" and should be functional, no matter other profiles are blocking my application inbound calls. 这是非常令人困惑的,因为我认为只有活动的配置文件应该是“活动的”并且应该是有效的,无论其他配置文件阻止我的应用程序入站呼叫。

I am using XPSP2 INetFwMgr interface to add exceptions which is lacking of "any" profile support. 我正在使用XPSP2 INetFwMgr接口来添加缺少“任何”配置文件支持的异常。

I am using c# but any language with example will be appreciated. 我正在使用c#,但任何语言都会受到赞赏。

You may try something like this: 你可以尝试这样的事情:

using System;
using NetFwTypeLib;

namespace FirewallManager

{
  class Program
  {
    static void Main(string[] args)
    {
        INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
        firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_ALLOW;
        firewallRule.Description = "Allow notepad";
        firewallRule.ApplicationName = @"C:\Windows\notepad.exe";
        firewallRule.Enabled = true;
        firewallRule.InterfaceTypes = "All";
        firewallRule.Name = "Notepad";

        INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(
            Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
        firewallPolicy.Rules.Add(firewallRule);

    }
  }
}

For sake of completeness, add reference to c:\\Windows\\System32\\FirewallAPI.dll 为了完整起见,请添加对c:\\ Windows \\ System32 \\ FirewallAPI.dll的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式将应用程序添加到 Windows 防火墙 - Programmatically add an application to Windows Firewall 在Vista +下安装服务并添加注册表项 - Install service and add registry entry under Vista+ 以编程方式管理 Windows 防火墙 - Programmatically manage Windows Firewall 以编程方式将规则添加到“具有高级安全性的Windows防火墙”管理单元? - Programmatically add rules to “Windows Firewall with Advanced Security snap-in”? 以编程方式将规则添加到AVG Firewall - Programmatically add rule to AVG Firewall 以编程方式杀死C#中vista / windows 7中的进程 - programmatically kill a process in vista/windows 7 in C# 如何使用Visual Studio开发可在所有Windows OS XP,Vista,7、8上运行的C#应用​​程序 - How to develop c# application using visual studio which will run on all windows OS xp,vista,7,8 如何在Windows Vista / 7的“默认程序”列表中添加我的应用程序? - How do I add my application in the Default Programs list of Windows Vista/7? 在Windows Vista> 8上获取默认的用户帐户配置文件图片 - Get default User Account Profile Picture on Windows Vista > 8 Windows Vista \\ 7上的应用程序清单,管理员权限和自动启动 - Application manifest, admin rights and autostart on Windows Vista\7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM