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.
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?
The best way to do it would be using
WMI
:Of course to do this you will need to be running the program as an administrator.
Hope this helps,
Jason.
The simplest approach is to have another program do the work for you. In this case, netsh.exe has a set of commands to control the Advanced Firewall that's used by Windows Vista and later. For example:
The default profiles are "domainprofile", "privateprofile", and "publicprofile", and the state is either "on" or "off".
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>
(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:
HNetCfg.FwMgr
netsh firewall
(netsh advfirewall
for Advanced Firewall)winmgmts:root/Microsoft/HomeNet
%windir%\Inf\Netfw.inf
(absent unless created manually)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 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).