ArticleDirectory
In the previous summary of C # (VB. NET) Operating Windows built-in firewall, we mentioned the following figure.
In this article, we will implementEnable/CloseAndAllow exceptions?Functions
First, because Windows comes with the "Security Center" Security Center FunctionProgramWhen the firewall is disabled, a prompt is displayed in the security center,
To solve this problem, you can close the security center by usingNet stopOrModify registryOr Windows service operations that come with. Net can all be done, so I won't be embarrassed.
Core Code :
C # method:
/// <Summary> /// Obtain the current firewall management policy /// </Summary> /// <Returns> return the object corresponding to the policy </returns> Private Static Object Firewallcurrentprofile (){ // Obtain the type of the COM component used to manage the Firewall Type fwmgrtype = type. gettypefromprogid (" Hnetcfg. fwmgr ", True ); // Create a COM component instance Object Fwmgr = activator. createinstance (fwmgrtype ); // Obtain the localpolicy attribute of the Instance Object Localpolicy = fwmgrtype. invokemember (" Localpolicy ", Bindingflags. getproperty, Null , Fwmgr, Null ); // Obtain the subattribute currentprofile of the localpolicy attribute Return Localpolicy. GetType (). invokemember (" Currentprofile ", Bindingflags. getproperty, Null , Localpolicy, Null );}
VB. NET:
Private FunctionFirewallprofile ()As ObjectDimFwmgrAs Object= Createobject ("Hnetcfg. fwmgr")ReturnFwmgr. localpolicy. currentprofilEnd Function
C # download the source code of VB. NETSource code(Leave a message if you need it. I am too lazy to write it, hey)
Original: http://www.zu14.cn/2009/01/15/dotnet-enable-disable-firewall/