-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonFirewallUpdate.bat
More file actions
56 lines (44 loc) · 1.31 KB
/
PythonFirewallUpdate.bat
File metadata and controls
56 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@echo off
setlocal
rem Check Administrator Permission
net session > nul 2>&1
if errorlevel 1 set ERR_MSG=Permission denied. & goto ERROR
rem Python Parameters
set PYTHON_PATH=C:\opt\Python27
set PYTHON_NAME=python
set PYTHON_DESC=Python
set PYTHON_CMDS=python pythonw
rem Virtualenv Parameters
set VENV_ROOT=C:\opt\venv
rem Delete firewall rules
netsh advfirewall firewall delete rule name="%PYTHON_NAME%"
rem Setup Python runtime
call :addRuntime "%PYTHON_NAME%" "%PYTHON_DESC%" "%PYTHON_PATH%" %PYTHON_CMDS%
rem Setup all Virtualenv runtime
for /f %%V in ('dir /a:d /b "%VENV_ROOT%"') do (
call :addRuntime "%PYTHON_NAME%" "%PYTHON_DESC%" "%VENV_ROOT%\%%V\Scripts" %PYTHON_CMDS%
)
:ERROR
if defined ERR_MSG echo %ERR_MSG%
endlocal
pause
exit /b 0
rem ---------------------------------------------
rem Sub Routine
rem ---------------------------------------------
rem Setup Python runtime
rem addRuntime name description path program...
:addRuntime
if not exist "%~3" exit /b 1
if not "%4" == "" (
call :addFirewall "%~1" "%~2" "%~3\%~4.exe"
shift /4
goto addRuntime
)
exit /b 0
rem Setup firewall rules
rem addFirewall name description program
:addFirewall
if not exist "%~3" exit /b 1
netsh advfirewall firewall add rule name="%~1" description="%~2" dir=in action=allow program="%~3"
exit /b 0