Skip to content

Commit

Permalink
Update Block_Steam.bat
Browse files Browse the repository at this point in the history
Shuffled the code around a bit so that
:ToggleFirewallRule

is it's own chunk of code. 
A bit like a function - but since batch files arn't great it's ran with a goto.
  • Loading branch information
8bitpineapple authored Nov 10, 2023
1 parent 1605981 commit 551d69e
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions Block_Steam.bat
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
@echo off
set "RuleName=Block_Steam"
set RuleName=Block_Steam

:: Check if the firewall rule exists
netsh advfirewall firewall show rule name="%RuleName%" > nul 2>&1

if %errorlevel% equ 0 (
:: Firewall Rule Exists
echo Firewall rule "%RuleName%" exists.
goto ToggleFireWallRule


:: Check if the rule is enabled
netsh advfirewall firewall show rule name="%RuleName%" | find "Enabled: No" > nul

if %errorlevel% equ 0 (
echo Enabling Internet Access for Steam
netsh advfirewall firewall set rule name="%RuleName%" new enable=no
echo Internet access available.
goto Done

) else (
echo Disabling Internet Access for Steam
netsh advfirewall firewall set rule name="%RuleName%" new enable=yes
echo Internet access disabled.
goto Done

)
) else (
:: Firewall Rule Doesn't Exist
echo Firewall rule "%RuleName%" does not exist.
Expand Down Expand Up @@ -64,6 +50,25 @@ if %errorlevel% neq 0 (
echo Firewall rule "%RuleName%" already exists. No action taken.
)

goto Done

:ToggleFireWallRule
:: Check if the rule is enabled
netsh advfirewall firewall show rule name="%RuleName%" | find "Enabled: Yes" > nul

if %errorlevel% equ 0 (
echo Enabling Internet Acess for Steam
netsh advfirewall firewall set rule name="%RuleName%" new enable=no
echo Internet access available.

) else (
echo Disabling Internet Acess for Steam
netsh advfirewall firewall set rule name="%RuleName%" new enable=yes
echo Internet access disabled.
)
goto Done


:Done
pause
exit /b

0 comments on commit 551d69e

Please sign in to comment.