我有C#应用程序使用PORT 777进行异步通信,PORT 3306用于与My Sql Server进行通信.端口被防火墙阻止时出现问题.我试图创建一个程序,在Windows 7的防火墙列表中添加一个例外.
当我运行程序时,我得到如下错误:"灾难性故障(HRESULT异常:0x8000FFFF(E_UNEXPECTED))".
我不明白这些错误是什么意思,欢迎提出任何建议,谢谢.
protected internal void AddExceptionToFirewall(){
try {
INetFwMgr fireWall = null;
INetFwAuthorizedApplications apps = null;
INetFwAuthorizedApplication app = null;
Type progID = null;
INetFwOpenPorts ports = null;
INetFwOpenPort asyncPort = null;
INetFwOpenPort mysqlPort = null;
bool appFounded = false;
bool asyncPortFounded = false;
bool mysqlPortFounded = false;
progID = Type.GetTypeFromProgID("HNetCfg.FwMgr");
// checking for Windows Firewall
fireWall = (INetFwMgr)Activator.CreateInstance(progID);
if (fireWall.LocalPolicy.CurrentProfile.FirewallEnabled) {
// obtain the list of authorized applications
apps = (INetFwAuthorizedApplications)fireWall.LocalPolicy.CurrentProfile.AuthorizedApplications;
IEnumerator appEnumerate …Run Code Online (Sandbox Code Playgroud)