Skip to content

Instantly share code, notes, and snippets.

@kipavy
Created January 12, 2026 17:03
Show Gist options
  • Select an option

  • Save kipavy/fde0ab811750be9ff3d15d38249faf76 to your computer and use it in GitHub Desktop.

Select an option

Save kipavy/fde0ab811750be9ff3d15d38249faf76 to your computer and use it in GitHub Desktop.
Batch script to auto-detect Steam paths and toggle Outbound Firewall rules for offline privacy.
<# :
@echo off
:: Batch section checks for Admin and launches PowerShell
setlocal
cd /d %~dp0
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting Admin privileges...
powershell -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-Expression ($(Get-Content '%~f0' -Raw))"
goto :eof
#>
# --- PowerShell Section Starts Here ---
# 1. Locate Steam Installation from Registry
try {
$regPath = "HKCU:\Software\Valve\Steam"
$rawPath = (Get-ItemProperty $regPath -ErrorAction Stop).SteamPath
$steamRoot = $rawPath.Replace('/', '\')
} catch {
Write-Host "Could not find Steam installation in Registry." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}
# 2. Define Targets (Main Executable + Helper)
# We search for steamwebhelper recursively in \bin\ because the folder name (cef.win64) changes often.
$helperPath = Get-ChildItem -Path "$steamRoot\bin" -Filter "steamwebhelper.exe" -Recurse | Select-Object -First 1 -ExpandProperty FullName
$targets = @(
@{ Name="Block_Steam_Main"; Path="$steamRoot\steam.exe" },
@{ Name="Block_Steam_Helper"; Path=$helperPath }
)
Write-Host "Steam Path Detected: $steamRoot" -ForegroundColor Cyan
Write-Host "----------------------------------------"
foreach ($t in $targets) {
if (-not $t.Path -or -not (Test-Path $t.Path)) {
Write-Host "Skipping $($t.Name): Path not found." -ForegroundColor Yellow
continue
}
$rule = Get-NetFirewallRule -DisplayName $t.Name -ErrorAction SilentlyContinue
if (-not $rule) {
# Create Rule if it doesn't exist
New-NetFirewallRule -DisplayName $t.Name -Program $t.Path -Direction Outbound -Action Block -Profile Any | Out-Null
Write-Host "Created Rule: $($t.Name) [BLOCKED]" -ForegroundColor Green
} else {
# Toggle Rule
if ($rule.Enabled -eq 'True') {
Set-NetFirewallRule -DisplayName $t.Name -Enabled False
Write-Host "Updated Rule: $($t.Name) -> [ALLOWED/DISABLED]" -ForegroundColor Gray
} else {
Set-NetFirewallRule -DisplayName $t.Name -Enabled True
Write-Host "Updated Rule: $($t.Name) -> [BLOCKED/ENABLED]" -ForegroundColor Red
}
}
}
Write-Host "----------------------------------------"
Write-Host "Done."
Start-Sleep -Seconds 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment