-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenableDefender.bat
164 lines (132 loc) · 3.2 KB
/
enableDefender.bat
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
::
:: Enable or disable automatic restart of defender after a reboot.
:: Won't work in Windows 11 at least since 22621
::
@echo off
setlocal enabledelayedexpansion
set my_name=%~n0%~x0
set my_dir="%~dp0"
set "my_dir=%my_dir:~1,-2%"
set /a enable=0
set /a check=0
set /a reboot=0
set "hklmSwPMWD=HKLM\SOFTWARE\Policies\Microsoft\Windows Defender"
GOTO :ParseParams
:ParseParams
REM IF "%~1"=="" GOTO Main
if [%1]==[/?] goto help
if [%1]==[/h] goto help
if [%1]==[/help] goto help
IF "%~1"=="/c" (
SET /a check=1
goto reParseParams
)
IF "%~1"=="/e" (
SET /a enable=1
goto reParseParams
)
IF "%~1"=="/d" (
SET /a enable=-1
goto reParseParams
)
IF "%~1"=="/r" (
SET /a reboot=1
goto reParseParams
)
IF "%~1"=="/v" (
SET /a verbose=1
goto reParseParams
)
IF "%~1"=="/h" (
goto help
)
:reParseParams
SHIFT
if [%1]==[] goto main
GOTO :ParseParams
:main
if %enable% NEQ 0 (
call :checkPermissions
if NOT %errorlevel% EQU 0 (
echo [e] Admin privileges required!
endlocal
exit /b -1
)
)
if %enable% EQU -1 (
call :disableDefender
) else (
if %enable% EQU 1 (
call :enableDefender
)
)
if %check% EQU 1 (
call :checkDefender
)
REM if %errorlevel% EQU 0 (
if %reboot% EQU 1 (
SET /P confirm="[?] Reboot now? (Y/[N])?"
IF /I "!confirm!" EQU "Y" (
shutdown /r /t 0
)
)
REM )
endlocal
exit /B %errorlevel%
:disableDefender
setlocal
echo [^>] disableDefender
reg add "%hklmSwPMWD%" /v DisableAntiSpyware /t REG_DWORD /d 0x00000001 /f
reg add "%hklmSwPMWD%" /v DisableAntiVirus /t REG_DWORD /d 0x00000001 /f
reg add "%hklmSwPMWD%" /v ServiceStartStates /t REG_DWORD /d 0x00000001 /f
endlocal
exit /B %errorlevel%
:enableDefender
setlocal
echo [^>] enableDefender
echo DisableAntiSpyware
reg delete "%hklmSwPMWD%" /v DisableAntiSpyware /f
echo.
echo DisableAntiVirus
reg delete "%hklmSwPMWD%" /v DisableAntiVirus /f
echo.
echo DisableAntiVirus
reg delete "%hklmSwPMWD%" /v ServiceStartStates /f
echo.
endlocal
exit /B %errorlevel%
:checkDefender
setlocal
echo [^>] checkDefender
echo DisableAntiSpyware
reg query "%hklmSwPMWD%" /v DisableAntiSpyware
echo.
echo DisableAntiVirus
reg query "%hklmSwPMWD%" /v DisableAntiVirus
echo.
echo DisableAntiVirus
reg query "%hklmSwPMWD%" /v ServiceStartStates
echo.
endlocal
exit /B %errorlevel%
:checkPermissions
echo [^>] checkPermissions
if [%verbose%]==[1] (
echo checking Admin permissions...
)
net session >nul 2>&1
exit /B %errorlevel%
:usage
echo Usage: %prog_name% [/e^|/d^|/c] [/r] [/v]
exit /B %errorlevel%
:help
call :usage
echo.
echo Options:
echo /c Check Windows Defender State
echo /d Disable Windows Defender
echo /e Enable Windows Defender
echo /r Reboot after confirmation
echo.
echo /v More verbose mode.
exit /B %errorlevel%