繁体   English   中英

为分布式事务处理协调器(msdtc.exe)添加防火墙规则

[英]Add a firewall rule for Distributed Transaction Coordinator (msdtc.exe)

我试图使用firewallAPI.dll来添加规则。 它适用于calc.exe(或其他一些文件),如下所述,但msdtc.exe失败,但有以下异常:

System.IO.FileNotFoundException:'系统找不到指定的文件。 (HRESULT异常:0x80070002)'

例:

static void Main(string[] args)
{
    var manager = GetFirewallManager();
    if (manager.LocalPolicy.CurrentProfile.FirewallEnabled)
    {
        var path = @"C:\Windows\System32\calc.exe";
        //var path = @"C:\Windows\System32\msdtc.exe"; // System.IO.FileNotFoundException: 'The system cannot find the file specified.
        AuthorizeApplication("Test", path, NET_FW_SCOPE_.NET_FW_SCOPE_ALL, NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY);
    }
}

private const string CLSID_FIREWALL_MANAGER =
    "{304CE942-6E39-40D8-943A-B913C40C9CD4}";

private static NetFwTypeLib.INetFwMgr GetFirewallManager()
{
    Type objectType = Type.GetTypeFromCLSID(
        new Guid(CLSID_FIREWALL_MANAGER));
    return Activator.CreateInstance(objectType)
        as NetFwTypeLib.INetFwMgr;
}

private const string PROGID_AUTHORIZED_APPLICATION =
    "HNetCfg.FwAuthorizedApplication";
public static bool AuthorizeApplication(string title, string applicationPath,
    NET_FW_SCOPE_ scope, NET_FW_IP_VERSION_ ipVersion)
{
    // Create the type from prog id
    Type type = Type.GetTypeFromProgID(PROGID_AUTHORIZED_APPLICATION);
    INetFwAuthorizedApplication auth = Activator.CreateInstance(type)
        as INetFwAuthorizedApplication;
    auth.Name = title;
    auth.ProcessImageFileName = applicationPath;
    auth.Scope = scope;
    auth.IpVersion = ipVersion;
    auth.Enabled = true;

    INetFwMgr manager = GetFirewallManager();
    manager.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(auth);
    return true;
}

注意:我检查了文件夹,看到文件位置正确...有人可以帮助为分布式事务处理协调器添加防火墙规则吗? 也许我应该尝试将另一个文件添加到防火墙(而不是msdtc.exe)?

单击项目>属性>构建选项卡,取消选中“首选32位”复选框。 你不喜欢它,没有32位版本的msdtc.exe。

文档系统重定向器导致FileNotFoundException的原因在本MSDN文章中有详细解释。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM