C # (VB. NET) enable/disable Windows Firewall

Source: Internet
Author: User
ArticleDirectory
    • Core code:

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.