Windows 7,8.1
当我尝试禁用 Windows防火墙时出现exception。 我试图用pipe理员权限来做到这一点。 但是对于Windows防火墙的启用,我并没有同样的问题。
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 @R_406_4045@ion: Method or operation is not emplemented yet.. mgr.LocalPolicy.CurrentProfile.FirewallEnabled = false;
我如何禁用Windows防火墙?
服务将文件写入不同的path
如何从本地应用程序获取窗口打开/closures/最小化消息?
.NET软件更新pipe理器
如何创build一个大的图标托盘?
Wix:将自定义操作中的文件复制到Programm目录(Windows 7)
dynamic添加控件时如何将面板滚动保持在最前面?
如何响应Windows服务的状态更改?
停止响应Windows命令
卸载框架4.6.2预览
在屏幕上自动点击鼠标
看来你正在使用Windows XP SP2的COM API,这是已知的问题在Windows Vista / 7和更新的版本。
建议您使用较新的API:
( 我没有测试过这个 )
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);
private const string CLSID_FIREWALL_MANAGER = "{304CE942-6E39-40D8-943A-B913C40C9CD4}"; private static NetFwTypeLib.INetFwMgr GetFirewallManager() { Type objectType = Type.GetTypeFromCLSID( new Guid(CLSID_FIREWALL_MANAGER)); return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr; } public static void Firewall() { INetFwMgr manager = GetFirewallManager(); bool isFirewallEnabled = manager.LocalPolicy.CurrentProfile.FirewallEnabled; manager.LocalPolicy.CurrentProfile.FirewallEnabled = false; }
在Main.cs中
yourclass.Firewall();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。