Skip to content

Instantly share code, notes, and snippets.

@xymopen
Created April 2, 2018 01:23
Show Gist options
  • Save xymopen/89316b6672e42bd9dbb134b8589a91f7 to your computer and use it in GitHub Desktop.
Save xymopen/89316b6672e42bd9dbb134b8589a91f7 to your computer and use it in GitHub Desktop.
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
set STUDENT_MAIN_PATH="C:\Program Files\Mythware\e-Learning Class\StudentMain.exe"
set LOCAL_INTERFACE="本地连接"
set FIREWALL_RULE_NAME_1="Block Mythware e-Learning class(UDP 4605)"
set FIREWALL_RULE_NAME_2="Block Mythware e-Learning class(StudentMain.exe)"
net stop "Student Service"
echo Enabling firewall for all profiles...
netsh advfirewall set allprofiles state on
netsh advfirewall firewall show rule name=%FIREWALL_RULE_NAME_1% > NUL
if errorlevel 1 (
echo Adding firewall rule...
netsh advfirewall firewall add rule name=%FIREWALL_RULE_NAME_1% dir=in action=block localport=4605 protocol=UDP
)
netsh advfirewall firewall show rule name=%FIREWALL_RULE_NAME_2% > NUL
if errorlevel 1 (
echo Adding firewall rule...
netsh advfirewall firewall add rule name=%FIREWALL_RULE_NAME_2% dir=in action=block program=%STUDENT_MAIN_PATH%
)
echo Enabling firewall rule...
netsh advfirewall firewall set rule name=%FIREWALL_RULE_NAME_1% new enable=yes
netsh advfirewall firewall set rule name=%FIREWALL_RULE_NAME_2% new enable=yes
:: re-enable network to kill local server
echo Disabling network...
netsh interface set interface %LOCAL_INTERFACE% admin=disable
echo Enabling network...
netsh interface set interface %LOCAL_INTERFACE% admin=enable
endlocal
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
set FIREWALL_RULE_NAME_1="Block Mythware e-Learning class(UDP 4605)"
set FIREWALL_RULE_NAME_2="Block Mythware e-Learning class(StudentMain.exe)"
echo Enabling firewall for all profiles...
netsh advfirewall set allprofiles state on
netsh advfirewall firewall show rule name=%FIREWALL_RULE_NAME_1% > NUL
if errorlevel 1 (
echo Adding firewall rule...
netsh advfirewall firewall add rule name=%FIREWALL_RULE_NAME_1% dir=in action=block localport=4605 protocol=UDP
)
netsh advfirewall firewall show rule name=%FIREWALL_RULE_NAME_2% > NUL
if errorlevel 1 (
echo Adding firewall rule...
netsh advfirewall firewall add rule name=%FIREWALL_RULE_NAME_2% dir=in action=block program=%STUDENT_MAIN_PATH%
)
echo Disabling firewall rule...
netsh advfirewall firewall set rule name=%FIREWALL_RULE_NAME_1% new enable=no
netsh advfirewall firewall set rule name=%FIREWALL_RULE_NAME_2% new enable=no
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment