-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllow Scripts.cmd
50 lines (46 loc) · 1.9 KB
/
Allow Scripts.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@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
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