Disable Windows Firewall & prevent notifications for the users to re-enable it

Please use the script to disable Windows Firewall and prevent Notifications for the users to re-enable the Firewall.

import _winreg
import os
from subprocess import PIPE, Popen
import ctypes
class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

with disable_file_system_redirection():
    OB = Popen('netsh advfirewall set allprofiles state off', shell=True, stdout = PIPE, stderr = PIPE)
RES = OB.communicate()
RET = OB.returncode
if RET == 0:
    print 'firewall is turned off successfully'
else:
    print RES[1]

lk = ['HKEY_CURRENT_USER\\Software\\Policies\\Microsoft\\Windows\\Explorer','HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\PushNotifications']
lv = ['DisableNotificationCenter', 'ToastEnabled']
lt = [_winreg.REG_DWORD, _winreg.REG_DWORD]
ld = [1, 0]
d = {'lk':lk, 'lv':lv, 'lt':lt, 'ld':ld}
rl = []
c = 0
for i in d['lk']:
    li = i.split(os.sep)
    rkey = getattr(_winreg, li[0])
    skey = os.sep.join(li[1:])
    try:
        ok = _winreg.OpenKey(rkey, skey, 0, _winreg.KEY_ALL_ACCESS)
    except:
        _winreg.CreateKeyEx(rkey, skey, 0, _winreg.KEY_ALL_ACCESS)
        ok = _winreg.OpenKey(rkey, skey, 0, _winreg.KEY_ALL_ACCESS)
    try:
        _winreg.SetValueEx(ok, d['lv'][c], 0, d['lt'][c], d['ld'][c])
        rl.append(1)
    except:
        rl.append(0)
    c += 1

if rl[0] == 1 and rl[1] == 1:
    print 'security notifications disabled successfully'
else:
    print 'sorry, security notifications not disabled!'

Sample Output:

Exported Scripts:

turn off firewall and disable security notifications.PNG

20161221-turn-off-firewall-and-disable-security-notifications.json (2.59 KB)