如何使用python禁用Windows防火墙 [英] How to disable Windows Firewall using python
问题描述
我正在尝试将自动化编写到我正在工作的一个小项目中. 在此过程中,我需要使用python 禁用Windows防火墙(对于每个Windows版本)(我更喜欢activepython,因为它已经安装了).
I am trying to write automation to a little project that I'm doing in work. In the proccess I need to disable Windows Firewall (for every Windows version) using python (I prefer activepython because it already installed).
我寻找了很多答案,但是没有找到适合我需要的答案.
I looked for many answers but I didn't found any answer that suits my needs.
我找到了这个网站: https://mail.python.org/pipermail/python-win32 /2012-July/012434.html 但是问题是,当我从控制面板检查实际 防火墙未禁用...
I found this site: https://mail.python.org/pipermail/python-win32/2012-July/012434.html But the problem is that when I check from the control panel the actual disabling of Firewall is not happening...
有人可以帮助我解决这个问题吗?
Can someone help me with this problem?
推荐答案
Ways to control Windows Firewall - both with UI and programmatically - are covered extensively in the Windows Firewall Tools and Settings MSDN article. They are:
-
注册表设置
Registry settings at
-
HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\<profile>
(本地设置)和 -
HKLM\SOFTWARE\Policies\Microsoft\WindowsFirewall\<profile>
(组策略设置).
HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\<profile>
(local settings) andHKLM\SOFTWARE\Policies\Microsoft\WindowsFirewall\<profile>
(group policy settings).
更改设置具有立竿见影的效果:防火墙服务显然会为按键设置通知.
Changing a setting has an instant effect: the Firewall service sets up notifications for the keys apparently.
可以使用这些设置的设施:
Facilities that work with the settings:
- COM接口
HNetCfg.FwMgr
-
netsh firewall
(对于高级防火墙,为netsh advfirewall
) - WMI
winmgmts:root/Microsoft/HomeNet
-
%windir%\Inf\Netfw.inf
(除非手动创建,否则不存在)
- COM interface
HNetCfg.FwMgr
netsh firewall
(netsh advfirewall
for Advanced Firewall)- WMI
winmgmts:root/Microsoft/HomeNet
%windir%\Inf\Netfw.inf
(absent unless created manually)
firewall.cpl
反映本地注册表设置(或如果存在则覆盖组策略设置) Windows防火墙的工作原理,XP/2003的"Windows防火墙配置文件确定"部分和
firewall.cpl
reflects the local registry settings (or overriding Group Policy ones if they are present and doesn't allow to change them) and the currently active profile (for predefined profiles and how one is selected, see How Windows Firewall Works, "Windows Firewall Profile Determination" section for XP/2003 and Understanding Firewall Profiles for Vista+).
Python可以与任何上述工具一起使用.尽管根据您的任务,其他工具(组策略,.reg
文件,netsh
命令行)可能更方便(例如netsh
自动选择活动配置文件).
Python can work with any of the aforementioned facilities. Though other tools (Group Policy, .reg
files, netsh
command line) may be more convenient depending on your task (e.g. netsh
auto-selects the active profile).
这篇关于如何使用python禁用Windows防火墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!