簡體   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