I'm writing a python script to make a rule in firewall, its a project for local application prevent my children of watching porn actually. I figure out that I need powershell, so I wrote this script, but still whenever python run a powershell command, powershell windows showing up, any ideas to hide it ?
from __future__ import print_function
from __future__ import print_function
import ctypes, sys
import subprocess
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if not(is_admin()):
if sys.version_info[0] == 3:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
cmd = 'PowerShell -Executionpolicy byPass -Command New-NetFirewallRule -DisplayName "System_x64" -Enable True -Profile Any -Action Block -Direction Outbound -RemoteAddress "8.8.8.8"'
check = subprocess.run("PowerShell -Executionpolicy byPass -Command Get-NetFirewallRule -DisplayName 'System_x64'", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if(check.returncode != 0):
rs = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)