forked from anic17/Batch-Antivirus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BAVAutorun.bat
114 lines (106 loc) · 4.04 KB
/
BAVAutorun.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
::BAV_:[email protected]:anic17/Batch-Antivirus.git
@echo off
setlocal EnableDelayedExpansion
title Batch Antivirus autorun script
echo.Batch Antivirus autorun script.
echo.
pushd "%~dp0"
call "%~dp0BAVStatus.bat" --skip || exit /b
echo.Searching for autorun installations...
for %%# in ("HKCU" "HKLM") do (
reg query "%%~#\Software\Microsoft\Windows\CurrentVersion\Run" /v "BAVAutoRun" > nul 2>&1 && echo. - Found %%~# hive
)
for /f "tokens=2* delims= " %%A in ('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit"') do (
set "regshell=%%B"
set "regshell=!regshell:"=!"
if "!regshell!"=="%~dp0RealTimeProtection.bat --autorun-userinit" echo. - Found shell autorun
)
echo.
echo.This script will install Batch Antivirus real time protection when the computer starts.
echo.It is highly recommended to run this script as an administrator.
echo.
echo.However, you shouldn't install more than 1 single autorun on the PC.
echo.
echo.Are you sure you want to run Batch Antivirus every time your computer starts? (y/n)
choice /c:YN /n > nul
if !errorlevel!==1 goto enable
if !errorlevel!==2 goto disable
echo.Unknown option
goto exit
:enable
echo.
echo.Autorun installation options:
echo. - Option 1: Current user (%username%)
echo. - Option 2: All users
echo. - Option 3: Shell (Recommended)
choice /c:123 /n >nul
if errorlevel 1 set regpath=HKCU
if errorlevel 2 set regpath=HKLM
if errorlevel 3 goto shellenable
echo.Installing autorun...
reg add "!regpath!\Software\Microsoft\Windows\CurrentVersion\Run" /v "BAVAutoRun" /t REG_SZ /d "\"%~dp0RealTimeProtection.bat\"" /f > nul 2>&1 || (
echo.Cannot write to the registry path. Try running this script with administrator privileges.
goto quit
)
echo.Checking autorun installation...
reg query "!regpath!\Software\Microsoft\Windows\CurrentVersion\Run" /v "BAVAutoRun" > nul 2>&1 && (
echo.Batch Antivirus autorun has been successfully installed. You can disable it any time you want.
) || (
echo.Failed to install autorun for Batch Antivirus^^!
)
echo.
goto quit
:disable
set /a found=0,deleted=0
for %%# in ("HKCU" "HKLM") do (
echo.Checking %%~# registry hive...
reg query "%%~#\software\Microsoft\Windows\CurrentVersion\Run" /v "BAVAutoRun" > nul 2>&1 && (
echo.Found autorun on %%~#: Removing...
set /a found+=1
reg delete "%%~#\Software\Microsoft\Windows\CurrentVersion\Run" /v "BAVAutoRun" /f > nul 2>&1 && (
set /a deleted+=1
echo.%%~# registry autorun deleted successfully.
echo.
) || (
echo.Failed to delete autorun on %%~# registry hive^^!
)
)
)
echo.Checking shell autorun...
for /f "tokens=2* delims= " %%A in ('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit"') do (
set "regshell=%%B"
set "regshell=!regshell:"=!"
if "!regshell!"=="%~dp0RealTimeProtection.bat --autorun-userinit" (
echo.Found shell autorun: Removing...
set /a found+=1
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit" /t REG_SZ /d "%SystemRoot%\System32\userinit.exe," /f > nul 2>&1 && (
set /a deleted+=1
echo.Shell autorun deleted successfully.
echo.
) || (
echo.Failed to delete shell autorun^^!
)
)
)
echo.Deleted !deleted! out of !found! Batch Antivirus autoruns.
echo.
:quit
echo.Press any key to quit...
popd
pause>nul
endlocal
exit /b !errorlevel!
:shellenable
echo.Installing shell autorun...
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit" /t REG_SZ /d "\"%~dp0RealTimeProtection.bat\" --autorun-userinit" /f > nul 2>&1 || (
echo.Cannot write to the registry path. Try running this script with administrator privileges.
goto quit
)
echo.Checking autorun shell installation...
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit" > nul 2>&1 && (
echo.Batch Antivirus shell autorun has been successfully installed. You can disable it any time you want.
) || (
echo.Failed to install autorun for Batch Antivirus^^!
)
echo.
goto quit