Disabling Windows Firewall with a BAT File

Disabling Windows Firewall with a BAT File

Sometimes I need to disable Windows Firewall on a Windows 10 or Windows 11 machine for lab testing.

I wanted a simple batch file I could run quickly when troubleshooting connectivity in a lab or controlled environment.

The script needs to be run as an Administrator, so it checks for elevated privileges before doing anything else.

I usually keep the .bat file on the Desktop.

To run it, right-click the file and select Run as administrator.

If the script is running with Administrator privileges, it will disable Windows Firewall for all profiles.

The batch file, which I keep on the Desktop as Disable-Windows-Firewall.bat:

@echo off
setlocal EnableExtensions

:: Check for administrator privileges
fltmc >nul 2>&1
if errorlevel 1 (
    echo ERROR: This script must be run as an administrator.
    echo Right-click this file and choose "Run as administrator".
    pause
    exit /b 1
)

echo Disabling Windows Firewall for all profiles...
netsh advfirewall set allprofiles state off

if errorlevel 1 (
    echo Failed to disable Windows Firewall. Check permissions and logs.
    pause
    exit /b 1
) else (
    echo Windows Firewall has been disabled for all profiles.
)

pause
exit /b 0

Discliamer: Be careful when using this command. Disabling the firewall lowers the security posture of the machine, so it should only be used for testing or other controlled situations.

Personally, I have enough systems in place on my lab network to protect any device, and found the Windows firewall more of a nuisance than anything else.

Restore Windows Firewall

Once testing is complete, Windows Firewall can be enabled again for all profiles from an elevated Command Prompt:

netsh advfirewall set allprofiles state on

You can confirm the current status with:

netsh advfirewall show allprofiles state

References

Windows Firewall netsh command reference:

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netsh-advfirewall