@echo off >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" if '%errorlevel%' NEQ '0' ( goto uacprompt ) else ( goto gotadmin ) :uacprompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotadmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :menu cls echo 1. Scripts: On (Recommended) echo 2. Scripts: Off echo. set /p choice=: if "%choice%"=="1" goto A if "%choice%"=="2" goto B goto menu :A cls :: allow double click powershell scripts reg add "HKCR\Applications\powershell.exe\shell\open\command" /ve /t REG_SZ /d "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -ExecutionPolicy unrestricted -File \"%%1\"" /f >nul 2>&1 :: allow powershell scripts reg add "HKCU\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Unrestricted" /f >nul 2>&1 reg add "HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Unrestricted" /f >nul 2>&1 :: unblock all files in current directory cd %~dp0 powershell -Command "Get-ChildItem -Path $PSScriptRoot -Recurse | Unblock-File" echo Enabled Powershell Scripts + Unblocked Files pause exit :B cls :: disallow double click powershell scripts reg delete "HKCR\Applications\powershell.exe" /f >nul 2>&1 reg delete "HKCR\ps1_auto_file" /f >nul 2>&1 :: disallow powershell scripts reg add "HKCU\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Restricted" /f >nul 2>&1 reg add "HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Restricted" /f >nul 2>&1 echo Disabled Powershell Scripts pause exit