如何禁用Windows防火墙?

编程入门 行业动态 更新时间:2024-10-26 14:37:07
本文介绍了如何禁用Windows防火墙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Windows 7、8.1

Windows 7, 8.1

尝试禁用 Windows防火墙时出现异常.我尝试使用管理员权限来执行此操作.但是对于Windows防火墙启用,我没有同样的问题.

I get an exception when I try to disable Windows Firewall. I try to do it with admin rights. But I haven't the same problem for Windows Firewall enabling.

Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false); INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType); // Get the Windows Firewall status bool firewallEnabled = mgr.LocalPolicy.CurrentProfile.FirewallEnabled; // it works fine... String frw_status = "Windows Firewall is " + (firewallEnabled ? "enabled" : "disabled"); // Enable or disable firewall. // I get the exception here when I try to disable Windows Firewall. // I have not problem when I try to enable Windows Firewall (it works fine). // // Exception message: // An unhandled exception of type 'System.NotImplementedException' // occurred in net_sandbox.exe // Additional information: Method or operation is not emplemented yet.. mgr.LocalPolicy.CurrentProfile.FirewallEnabled = false;

如何禁用Windows防火墙?

How can I disable Windows Firewall?

推荐答案

似乎您正在使用Windows XP SP2 COM API,该API在Windows Vista/7和更高版本上存在问题.

It seems you're using Windows XP SP2 COM API, which is known to have issues on Windows Vista/7 and newer versions.

建议您使用较新的API:

It's recommended that you use the newer API:

( 我还没有测试过 )

(I have not tested this)

Type netFwPolicy2Type = Type.GetTypeFromProgID("HNetCfg.FwPolicy2"); INetFwPolicy2 mgr = (INetFwPolicy2)Activator.CreateInstance(netFwPolicy2Type); // Gets the current firewall profile (domain, public, private, etc.) NET_FW_PROFILE_TYPE2_ fwCurrentProfileTypes = (NET_FW_PROFILE_TYPE2_)mgr.CurrentProfileTypes; // Get current status bool firewallEnabled = mgr.get_FirewallEnabled(fwCurrentProfileTypes); string frw_status = "Windows Firewall is " + (firewallEnabled ? "enabled" : "disabled"); // Disables Firewall mgr.set_FirewallEnabled(fwCurrentProfileTypes, false);

更多推荐

如何禁用Windows防火墙?

本文发布于:2023-08-06 04:38:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310121.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:防火墙   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!