将C#应用程序添加到Windows 7的域网络的防火墙例外列表中 [英] Add C# application to firewall exception list to the Domain network of windows 7

查看:255
本文介绍了将C#应用程序添加到Windows 7的域网络的防火墙例外列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想将我的应用添加到防火墙例外列表中.它在XP上运行良好,但是在安装Windows 7时,它被添加到防火墙例外列表中,但是域"部分却被添加到防火墙例外列表中.仍未选中.因此,我的应用被防火墙阻止了.在这里,我复制代码.

INetFwAuthorizedApplications

Hi
I want to add my aplication to the firewall exception list. it is working well with XP, but when in installing windows 7, it is added to the firewall exception list but the "Domain" is still unchecked. Therefore my aplication is blocked by the firewall. Here i copying the code.

INetFwAuthorizedApplications

应用程序;

 

applications;

 

 

INetFwAuthorizedApplication 应用程序;

INetFwAuthorizedApplication application;

 

 

私有 btnAuthenticate_Click( 发件人 e)

 

private void btnAuthenticate_Click(object sender, EventArgs e)

 

INetFwAuthorizedApplication )getInstance( "INetAuthApp" );

INetFwAuthorizedApplication)getInstance("INetAuthApp");

 

 

"myApp" ;

"myApp";

 

 

@"C:\ Program Files \ EIS \ Test \ myApp.exe"

 

@"C:\Program Files\EIS\Test\myApp.exe";

 

 

true ;

true;

 

 

类型 NetFwMgrType = 类型 .GetTypeFromProgID(

 

Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);

 

 

INetFwMgr mgr =( INetFwMgr ) .CreateInstance(NetFwMgrType);

INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);

 

 

INetFwAuthorizedApplications )mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;

 

INetFwAuthorizedApplications)mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;

 

applications.Add(应用程序);

applications.Add(application);

}

请帮助!

注意事项
Rajesh VR

}

Please help!!!

Regards
Rajesh VR

应用程序=(

 

 

application.Enabled =

application.Enabled =

application.ProcessImageFileName =

application.ProcessImageFileName =

application.Name =

application.Name =

{

application =(

application = (

 

 

推荐答案


尝试类似的方法,看看是否可行:

INetFwAuthorizedApplications应用程序;
INetFwAuthorizedApplication应用程序;
应用程序.Name="Internet Explorer"/*设置应用程序名称*/
  
/*将此属性设置为应用程序可执行文件的位置*/
application.ProcessImageFileName ="C:\\ Program Files \\ Internet Explorer \\ iexplore.exe"
   
应用程序.Enabled= 真的; //启用它
/*现在将此应用添加到AuthorizedApplications集合中*/
 
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr",false);
INetFwMgr mgr =(INetFwMgr)Activator.CreateInstance(NetFwMgrType);
应用程序=(INetFwAuthorizedApplications)mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;
applications.Add(应用程序);


也就是说,所有这些API均为Windows XP级别并且它们应该可以在Windows Vista/Windows 7中正常运行.但是,建议您将新的COM API(INetFwPolicy2)用于Vista/Win7.您可以在此处 http://msdn.microsoft.com/zh-CN//library/aa366418%28VS.85%29.aspx
这些API更好而且更易于使用.他们每个人都有例子.


Try something like this and see if it works:

INetFwAuthorizedApplications applications; 
INetFwAuthorizedApplication application;
   
application.Name = “Internet Explorer”;/*set the name of the application */
   
/* set this property to the location of the executable file of the application*/
 application.ProcessImageFileName = "C:\\Program Files\\Internet Explorer\\iexplore.exe" 
    
application.Enabled =  true; //enable it
/*now add this application to AuthorizedApplications collection */
 
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
applications = (INetFwAuthorizedApplications)mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;
applications.Add(application);


That said, all these API are Windows XP level and they should work alright in Windows Vista/Windows 7. But, it is recommended that you use the newer COM API (INetFwPolicy2) for Vista/Win7. You can read about them here http://msdn.microsoft.com/en-us/library/aa366418%28VS.85%29.aspx
These API are much better and simpler to use. They have examples for each one too.


这篇关于将C#应用程序添加到Windows 7的域网络的防火墙例外列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆