积极答复者
c# 操作防火墙添加入站和删除入站问题

问题
-
在引用里,选择 COM 页, 找到 NetFwTypeLib,本人操作系统service 2008,经测试代码,添加可以,但是调用 Remove 移除发现防火墙里添加的还存在无法删除,也没错误异常,求大事解答,还有为什么添加到防火墙入站在里面看到都是2个一样的
//创建firewall管理类的实例 INetFwMgr netFwMgr = (INetFwMgr)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwMgr")); //创建一个认证程序类的实例 INetFwAuthorizedApplication app = (INetFwAuthorizedApplication)Activator.CreateInstance( Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication")); //在例外列表里,程序显示的名称 app.Name = "自定义"; //程序的决定路径,这里使用程序本身 app.ProcessImageFileName = Application.ExecutablePath; //是否启用该规则 app.Enabled = true; //加入到防火墙的管理策略 netFwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(app); //删除入站 INetFwMgr netFwMgr = (INetFwMgr)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwMgr")); //参数为程序的绝对路径 netFwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications.Remove(Application.ExecutablePath)
啥叫乐观-得瑟的最高境界
- 已编辑 极度 2013年9月26日 9:04 添加描述
答案
-
使用同一个firewall管理类的实例来删除,即删除你倒数第二行的代码,更多内容可以参考下面的文章:
http://www.codeproject.com/Articles/14906/Open-Windows-Firewall-During-Installation
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample
- 已标记为答案 Jason Dot WangModerator 2013年10月7日 10:07
全部回复
-
使用同一个firewall管理类的实例来删除,即删除你倒数第二行的代码,更多内容可以参考下面的文章:
http://www.codeproject.com/Articles/14906/Open-Windows-Firewall-During-Installation
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample
- 已标记为答案 Jason Dot WangModerator 2013年10月7日 10:07