gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 18:30:47 26 4
gpt4 key购买 nike

我尝试使用 firewallAPI.dll 添加规则。它对 calc.exe(或其他一些文件)工作正常,如下所述,但对 msdtc.exe 失败,但出现以下异常:

System.IO.FileNotFoundException: 'The system cannot find the file specified. (Exception from 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)?

最佳答案

Project > Properties > Build 选项卡,取消选中“Prefer 32-bit”复选框。你不喜欢它,没有 32 位版本的 msdtc.exe。

为什么文件系统重定向器导致 FileNotFoundException 在 this MSDN article 中有很好的解释.

关于c# - 为分布式事务处理协调器 (msdtc.exe) 添加防火墙规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44338484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com