1
我需要在域網絡防火牆中爲我的應用程序打開特定端口。如何在域網絡中打開端口防火牆
我曾嘗試這樣的代碼:
INetFwOpenPorts ports;
INetFwOpenPort port = (INetFwOpenPort)Activator.CreateInstance(
Type.GetTypeFromProgID("HNetCfg.FWOpenPort")); ;
port.Port = 8000; /* port no */
port.Name = "Application1"; /*name of the application using the port */
port.Enabled = true; /* enable the port */
port.Scope = NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
port.Protocol = NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP;//.NET_FW_IP_PROTOCO L_TCP;
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
ports = (INetFwOpenPorts)mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts;
ports.Add(port);
,但它不工作!並且我的數據不會發送,直到Windows防火牆中的域網絡爲ON!