In the previous articles, I talked about some operations on the firewall. What do I do today?AddAndDeleteAllow firewall programs to enter the exception list
In this article, we use com references, because the operations are too complicated without com references.
1. Add com references
In reference, select the com page and findNetfwtypelib, OK
II. Introduction of namespaces
using NetFwTypeLib;
3. Add exceptions that allow access through the firewall
// Create an instance of the firewall management class, inetfwmgr netfwmgr = (inetfwmgr) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwmgr "); // create an instance of the authentication program class inetfwauthorizedapplication APP = (inetfwauthorizedapplication) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwauthorizedapplication "); // In the exception list, the name displayed by the program is app. name = "Custom"; // specifies the path of the program. The app is used here. processimagefilename = application. executablepath; // whether to enable the rule app. enabled = true; // The Management Policy netfwmgr added to the firewall. localpolicy. currentprofile. authorizedapplications. add (APP );
4. delete a program in the exception list
Inetfwmgr netfwmgr = (inetfwmgr) activator. createinstance (type. gettypefromprogid ("hnetcfg. fwmgr "); // The parameter is the absolute path of the program netfwmgr. localpolicy. currentprofile. authorizedapplications. remove (application. executablepath );