forked from nmap/npcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FixInstall.bat
98 lines (86 loc) · 2.88 KB
/
FixInstall.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
@echo off
rem Start type auto will start the Npcap service at boot. Set this to "demand" for demand start instead.
set START_TYPE=system
setlocal ENABLEEXTENSIONS
rem Get the installed configuration
set KEY_NAME=HKLM\SYSTEM\CurrentControlSet\Services\npcap\Parameters
for /F "usebackq tokens=1,2*" %%A IN (`reg query "%KEY_NAME%" /v "Dot11Support" 2^>nul ^| find "Dot11Support"`) do (
set Dot11Support=%%C
)
echo Dot11Support = %Dot11Support%
for /F "usebackq tokens=1,2*" %%A IN (`reg query "%KEY_NAME%" /v "LoopbackSupport" 2^>nul ^| find "LoopbackSupport"`) do (
set LoopbackSupport=%%C
)
echo LoopbackSupport = %LoopbackSupport%
for /F "usebackq tokens=1,2*" %%A IN (`reg query "%KEY_NAME%" /v "WinPcapCompatible" 2^>nul ^| find "WinPcapCompatible"`) do (
set WinPcapCompatible=%%C
)
echo WinPcapCompatible = %WinPcapCompatible%
rem Make sure we can find where Npcap is installed
set KEY_NAME=HKLM\Software\WOW6432Node\Npcap
for /F "usebackq tokens=1,2*" %%A IN (`reg query "%KEY_NAME%" /ve 2^>nul ^| find "REG_SZ"`) do (
set NPCAP_DIR=%%C
)
if defined NPCAP_DIR (goto DO_FIX)
set KEY_NAME=HKLM\Software\Npcap
for /F "usebackq tokens=1,2*" %%A IN (`reg query "%KEY_NAME%" /ve 2^>nul ^| find "REG_SZ"`) do (
set NPCAP_DIR=%%C
)
if defined NPCAP_DIR (goto DO_FIX) else (goto ABORT)
:DO_FIX
echo NPCAP_DIR = "%NPCAP_DIR%"
rem Stop the services and set their start types properly
net stop npcap
sc.exe config npcap start= %START_TYPE%
if %Dot11Support% == 0x1 (
net stop npcap_wifi
rem *_wifi service is disabled at install
sc.exe config npcap_wifi start= disabled
)
if %WinPcapCompatible% == 0x1 (
net stop npf
sc.exe config npf start= %START_TYPE%
if %Dot11Support% == 0x1 (
net stop npf_wifi
sc.exe config npf_wifi start= disabled
)
)
rem Remove and reinstall loopback adapters
if %LoopbackSupport% == 0x1 (
"%NPCAP_DIR%\NPFInstall.exe" -ul
)
rem TODO Remove any leftover adapters in any case
netsh interface show interface | find "Npcap Loopback Adapter"
if NOT ERRORLEVEL 1 (
echo Some Npcap Loopback Adapter was not removed. Remove it manually:
echo 1. In the Device Manager, open 'Network adapters'
echo 2. Right-click any 'Npcap Loopback Adapter' and choose 'Uninstall device'
echo 3. Repeat until all Npcap Loopback Adapters are removed
start devmgmt.msc
pause
)
if %LoopbackSupport% == 0x1 (
"%NPCAP_DIR%\NPFInstall.exe" -il
)
rem Start the Base Filtering Engine in case it was disabled
sc.exe config bfe start= auto
net start bfe
rem Restart the services
net start npcap
if %WinPcapCompatible% == 0x1 (
net start npf
)
rem Rebind the filters to all adapters
if %Dot11Support% == 0x1 (
"%NPCAP_DIR%\NPFInstall.exe" -r2
) else (
"%NPCAP_DIR%\NPFInstall.exe" -r
)
if %WinPcapCompatible% == 0x1 (
"%NPCAP_DIR%\NPFInstall2.exe" -r
)
rem Done!
goto EOF
:ABORT
echo "Unable to find or fix your installation"
:EOF