XP Windows Firewall

Source: Internet
Author: User
// Fwconsole. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include" windows. H "# include <netfw. h> int main () {hresult hR = e_fail; inetfwmgr * pfwmgr = NULL; inetfwpolicy * pfwpolicy = NULL; coinitialize (null); HR = cocreateinstance (clsid_netfwmgr, null, deleted, iid_inetfwmgr, (void **) & pfwmgr); If (succeeded (HR) & pfwmgr) {If (succeeded (pfwmgr-> get_localpolicy (& pfwpolicy) {inetfwprofile * pfwprofile = NULL; If (succeeded (pfwpolicy-> get_currentprofile (& pfwprofile) {// checks whether the firewall allows the exception variant_bool bw.alowed; if (succeeded (pfwprofile-> get_exceptionsnotallowed (& bexcepalowed) {printf ("not allowed exception");} else {printf ("allowed exception ");} // indicates whether the firewall has enabled variant_bool bopend; If (succeeded (pfwprofile-> get_firewallenabled (& bopend) {printf ("\ nopened ");} else {printf ("\ nclosed"); // turn the firewall on. pfwprofile-> put_firewallenabled (variant_true); printf ("\ nthe firewall is now on. \ n ") ;}// indicates whether to notify variant_bool bnotify when the firewall blocks the program; If (succeeded (pfwprofile-> get_icationicationsdisabled (& bnotify) {printf ("\ nnot policy");} else {printf ("\ nnotify");} // check whether the port is added to the firewall inetfwopenports * pfwopenports = NULL; inetfwopenport * pfwopenport = NULL; pfwprofile-> get_globallyopenports (& pfwopenports); HR = cocreateinstance (_ uuidof (netfwopenport), null, temperature, _ uuidof (temperature ), (void **) & pfwopenport); If (succeeded (HR) & pfwopenports) {hR = pfwopenports-> item (9999, net_fw_ip_protocol_tcp/* include TCP and UDP */, & pfwopenport); If (succeeded (HR) & pfwopenport) {variant_bool benable; HR = pfwopenport-> get_enabled (& benable); If (succeeded (HR) & benable) {printf ("\ n9999 is enabled. ");} else {printf (" \ n9999 is not enabled. ") ;}} else {// create an instance of an open port. hR = cocreateinstance (_ uuidof (netfwopenport), null, clsctx_inproc_server, _ uuidof (inetfwopenport), (void **) & pfwopenport); If (succeeded (HR )) {pfwopenport-> put_port (9999); pfwopenport-> put_protocol (Protocol); pfwopenport-> put_enabled (variant_true); pfwopenport-> put_name (_ T ("firewalltest ")); if (s_ OK = pfwopenports-> Add (pfwopenport) {printf ("\ nadd 9999 port. ");} else {printf (" \ nadd 9999 port failed. ") ;}}}// inetfwauthorizedapplications * pfwauthapps = NULL; inetfwauthorizedapplication * pfwauthapp = NULL; // cocreateinstance (_ uuidof (inetfwauthorizedapplications), null, required, _ uuidof (inetfwauthorizedapplications), (void **) & pfwauthapps); HR = pfwprofile-> get_authorizedapplications (& pfwauthapps); If (succeeded (HR) & pfwauthapps) {hR = cocreateinstance (clsid_netfwauthorizedapplication, null, clsctx_all, iid_inetfwauthorizedapplication, (void **) & pfwauthapp); If (succeeded (HR )) {// Add the app rule BSTR bstr122 = sysallocstring (_ T ("D: \ fwtest.exe"); BSTR bstr121 = sysallocstring (_ T ("fwtest ")); pfwauthapp-> put_name (bstr121); pfwauthapp-> put_processimagefilename (bstr122); HR = pfwauthapps-> Add (pfwauthapp); If (succeeded (HR )) {printf ("\ nadd fwtest.exe app");} else {printf ("\ nadd fwtest.exe failed");} sysfreestring (bstr122); sysfreestring (bstr121 );}}}}} couninitialize (); System ("pause ");}

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.