Utility To Backup And Restore Security Settings


Caxtin

Well-known member
Member
Local time
4:46 PM
Posts
117
OS
Windows 11 Pro 64-bit / 24H2 / Build 26100.6584
Hello folks.
I have two old apps I still use; I'll keep using till they will not work anymore.
Once in a while, I would need to re-install them, especially after a major Windows update. Both apps can get finiky with the modern security components.

I would think there is a simply Method / Utility to Save / Backup and Restore security settings. That is, when I turn off all the security, including firewall, I would be able to use a utility to save that state or settings. When done with the installing the app, I can restore my system security state. Sometimes, after enabling the items I turned off, I tend to miss some sub switch or switches.

Cheers
 
Windows Build/Version
Windows 11 Pro 64-Bit / Version 24H2 (OS Build 26.100.2314)

My Computers

System One System Two

  • OS
    Windows 11 Pro 64-bit / 24H2 / Build 26100.6584
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell XPS 8960
    CPU
    Intel(R) Core(TM) i7-13700, 16 Core(s)
    Motherboard
    Dell Inc. Base Board.
    Memory
    Total: 64.00 GB
    Graphics Card(s)
    NVIDIA GeForce RTX 4060 Ti
    Sound Card
    Realtek Audio & Integrated NVIDIA High Definition Audio
    Monitor(s) Displays
    Three Dell Monitors
    Screen Resolution
    1920 x 1080
    Hard Drives
    1TB ATA
    1TB ATA
    2TB ATA
    2TB ATA
    Keyboard
    Dell Keyboard
    Mouse
    Wireless Mouse
    Internet Speed
    935 Mbs (Down) 31 Mbs (Up)
    Browser
    Google Chrome. Firefox. Opera.
    Antivirus
    Windows Defender
    Other Info
    TP-Link Gigabit PCI Express Adapter (Ethernet 802.3)
    Sophos TAP Adapter Provider (Ethernet 802.3)
  • Operating System
    Microsoft Windows 11 Home 64-bit. 22631 Multiprocessor Free
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspiron 15-3530
    CPU
    13th Gen Intel(R) Core(TM) i7-1355U
    Motherboard
    Dell Inc. 0122F5
    Memory
    Total Memory: 16.00 GB Usable Memory: 15.69 GB
    Graphics card(s)
    Intel(R) Iris(R) Xe Graphics
    Sound Card
    (1) Intel® Smart Sound Technology for Bluetooth® Audio (2) Intel® Smart Sound Technology for USB Audio (3) Realtek Audio
    Monitor(s) Displays
    Integrated
    Screen Resolution
    1920 x 1080
    Hard Drives
    NVMe PC SN740 NVMe WD 512GB
    PSU
    Integrated
    Keyboard
    Integrated
    Mouse
    Integrated
    Internet Speed
    143 Mbs Down / 43 Mbs Up
    Browser
    Google Chrome . Firefox
    Antivirus
    Windows Defender
Batch script i posted works for Windows 10 but should also work for Windows 11.

Code:
:: Backup and Restore Firewall Rules in Windows 10

@Echo Off & Cls


(Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)

Setlocal EnableDelayedExpansion

:choice

Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo        Backup Firewall Rules   (B)?   
Echo.       
Echo        Restore Firewall Rules  (R)?
Echo.


Set /p input= RESPONSE:

If /i  Not %input%==B (Goto :_Ex) Else (Goto :_Backup)

:_Ex
If /i Not %input%==R  (Goto :choice) Else (Goto :_Restore)



:_Backup
    mode con cols=95 lines=5 & color 0E
    Call :BrowseForFolder "Please choose the source folder for to backup Firewall Rules" SourceFolder
    If defined SourceFolder (
        echo(
        echo             You chose "!SourceFolder!" as source folder
    ) else (
        echo(
        Color 0C & echo                    The source folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )

netsh advfirewall export "!SourceFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo         Backing Firewall Rules
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit



:_Restore
    mode con cols=95 lines=5 & color 0E
    
    Call :BrowseForFolder "Please choose the target folder for to restore Firewall RulesFirewall Rules" TargetFolder
    If defined TargetFolder (
        echo(
        echo             You chose "!TargetFolder!" as Target folder
    ) else (
        echo(
        Color 0C & echo                    The Target folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )


netsh advfirewall import "!TargetFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo        Restoring Firewall Rules 
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit

    :BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
Batch script i posted works for Windows 10 but should also work for Windows 11.

Code:
:: Backup and Restore Firewall Rules in Windows 10

@Echo Off & Cls


(Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)

Setlocal EnableDelayedExpansion

:choice

Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo        Backup Firewall Rules   (B)? 
Echo.     
Echo        Restore Firewall Rules  (R)?
Echo.


Set /p input= RESPONSE:

If /i  Not %input%==B (Goto :_Ex) Else (Goto :_Backup)

:_Ex
If /i Not %input%==R  (Goto :choice) Else (Goto :_Restore)



:_Backup
    mode con cols=95 lines=5 & color 0E
    Call :BrowseForFolder "Please choose the source folder for to backup Firewall Rules" SourceFolder
    If defined SourceFolder (
        echo(
        echo             You chose "!SourceFolder!" as source folder
    ) else (
        echo(
        Color 0C & echo                    The source folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )

netsh advfirewall export "!SourceFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo         Backing Firewall Rules
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit



:_Restore
    mode con cols=95 lines=5 & color 0E
  
    Call :BrowseForFolder "Please choose the target folder for to restore Firewall RulesFirewall Rules" TargetFolder
    If defined TargetFolder (
        echo(
        echo             You chose "!TargetFolder!" as Target folder
    ) else (
        echo(
        Color 0C & echo                    The Target folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )


netsh advfirewall import "!TargetFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo        Restoring Firewall Rules
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit

    :BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b[/CODE
[/QUOTE]

Batch script i posted works for Windows 10 but should also work for Windows 11.

Code:
:: Backup and Restore Firewall Rules in Windows 10

@Echo Off & Cls


(Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)

Setlocal EnableDelayedExpansion

:choice

Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo        Backup Firewall Rules   (B)?  
Echo.      
Echo        Restore Firewall Rules  (R)?
Echo.


Set /p input= RESPONSE:

If /i  Not %input%==B (Goto :_Ex) Else (Goto :_Backup)

:_Ex
If /i Not %input%==R  (Goto :choice) Else (Goto :_Restore)



:_Backup
    mode con cols=95 lines=5 & color 0E
    Call :BrowseForFolder "Please choose the source folder for to backup Firewall Rules" SourceFolder
    If defined SourceFolder (
        echo(
        echo             You chose "!SourceFolder!" as source folder
    ) else (
        echo(
        Color 0C & echo                    The source folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )

netsh advfirewall export "!SourceFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo         Backing Firewall Rules
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit



:_Restore
    mode con cols=95 lines=5 & color 0E
   
    Call :BrowseForFolder "Please choose the target folder for to restore Firewall RulesFirewall Rules" TargetFolder
    If defined TargetFolder (
        echo(
        echo             You chose "!TargetFolder!" as Target folder
    ) else (
        echo(
        Color 0C & echo                    The Target folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )


netsh advfirewall import "!TargetFolder!\firewall_rules_backup.wfw"


Cls & Mode CON  LINES=11 COLS=40 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo.
Echo        Restoring Firewall Rules
Echo.
Echo.
Echo.
Ping -n 5 localhost >Nul

Exit

    :BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
Hello, thanks for the code you sent.
Would you please explain how it's used to backup and restore the system security settings?

Also, I went to the Windows security setting, and assumed I turned everything off, but apparently I did not, and cannot fine what's left since something is still sensing the old app I need to install. I wish something (utility) would be able to get all the necessary items to be disabled. Your code looks powerful to do a lot.

I went to your YouTube channel; I tagged it to visit it later.

Cheers
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 64-bit / 24H2 / Build 26100.6584
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell XPS 8960
    CPU
    Intel(R) Core(TM) i7-13700, 16 Core(s)
    Motherboard
    Dell Inc. Base Board.
    Memory
    Total: 64.00 GB
    Graphics Card(s)
    NVIDIA GeForce RTX 4060 Ti
    Sound Card
    Realtek Audio & Integrated NVIDIA High Definition Audio
    Monitor(s) Displays
    Three Dell Monitors
    Screen Resolution
    1920 x 1080
    Hard Drives
    1TB ATA
    1TB ATA
    2TB ATA
    2TB ATA
    Keyboard
    Dell Keyboard
    Mouse
    Wireless Mouse
    Internet Speed
    935 Mbs (Down) 31 Mbs (Up)
    Browser
    Google Chrome. Firefox. Opera.
    Antivirus
    Windows Defender
    Other Info
    TP-Link Gigabit PCI Express Adapter (Ethernet 802.3)
    Sophos TAP Adapter Provider (Ethernet 802.3)
  • Operating System
    Microsoft Windows 11 Home 64-bit. 22631 Multiprocessor Free
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspiron 15-3530
    CPU
    13th Gen Intel(R) Core(TM) i7-1355U
    Motherboard
    Dell Inc. 0122F5
    Memory
    Total Memory: 16.00 GB Usable Memory: 15.69 GB
    Graphics card(s)
    Intel(R) Iris(R) Xe Graphics
    Sound Card
    (1) Intel® Smart Sound Technology for Bluetooth® Audio (2) Intel® Smart Sound Technology for USB Audio (3) Realtek Audio
    Monitor(s) Displays
    Integrated
    Screen Resolution
    1920 x 1080
    Hard Drives
    NVMe PC SN740 NVMe WD 512GB
    PSU
    Integrated
    Keyboard
    Integrated
    Mouse
    Integrated
    Internet Speed
    143 Mbs Down / 43 Mbs Up
    Browser
    Google Chrome . Firefox
    Antivirus
    Windows Defender
Batch script only backup and restores Firewall rules, i don't know what you want me to explain?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
Hello folks.
I have two old apps I still use; I'll keep using till they will not work anymore.
Once in a while, I would need to re-install them, especially after a major Windows update. Both apps can get finiky with the modern security components.

I would think there is a simply Method / Utility to Save / Backup and Restore security settings. That is, when I turn off all the security, including firewall, I would be able to use a utility to save that state or settings. When done with the installing the app, I can restore my system security state. Sometimes, after enabling the items I turned off, I tend to miss some sub switch or switches.

Cheers

To export the per-app Security settings to a XML config file, run this command from an elevated (Admin) window:
Code:
powershell Get-ProcessMitigation -RegistryConfigFilePath C:\some\path\filename.xml

To reload the saved settings:
Code:
powershell Set-ProcessMitigation -RegistryConfigFilePath C:\some\path\filename.xml



Example for a custom per-app setting:
Code:
  <AppConfig Executable="HELLO.exe">
    <DynamicCode BlockDynamicCode="false" AllowThreadsToOptOut="false" />
    <ImageLoad BlockRemoteImageLoads="false" BlockLowLabelImageLoads="false" />
  </AppConfig>
 

My Computer

System One

  • OS
    Windows 7

Latest Support Threads

Back
Top Bottom