-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall_git.cmd
88 lines (76 loc) · 2.98 KB
/
uninstall_git.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
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
@echo off
setlocal enabledelayedexpansion
:: Array of possible Git installation locations
set "locations[0]=%ProgramFiles%\Git"
set "locations[1]=%SystemDrive%\Program Files (x64)\Git"
set "locations[2]=%ProgramFiles(x86)%\Git"
set "locations[3]=%SystemDrive%\Git"
set "locations[4]=%LOCALAPPDATA%\Programs\Git"
set "found_installations=0"
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script requires administrator privileges.
echo Please right-click and select "Run as administrator".
timeout /t 5 /nobreak
exit /b 1
)
echo Checking for Git installations...
for /L %%i in (0,1,4) do (
if exist "!locations[%%i]!\unins*.exe" (
set "uninstaller=!locations[%%i]!\unins*.exe"
for %%f in ("!uninstaller!") do (
set "found_uninstaller=%%f"
set /a found_installations+=1
)
)
)
if %found_installations% equ 0 (
echo No Git installations found in standard locations.
echo This might be because Git is installed in a non-standard location.
echo If you think Git is still installed, try to uninstall it through Control Panel or locate the installation folder and run the uninstaller manually.
timeout /t 5 /nobreak
exit /b 2
)
for /L %%i in (0,1,4) do (
if exist "!locations[%%i]!\unins*.exe" (
echo Found Git installation in !locations[%%i]!
echo With uninstaller !found_uninstaller!
echo Terminating running Git processes...
taskkill /F /IM "bash.exe" >nul 2>nul
taskkill /F /IM "putty.exe" >nul 2>nul
taskkill /F /IM "puttytel.exe" >nul 2>nul
taskkill /F /IM "puttygen.exe" >nul 2>nul
taskkill /F /IM "pageant.exe" >nul 2>nul
echo Uninstalling Git from !locations[%%i]!...
start /wait "Uninstalling Git" "!found_uninstaller!" /SP- /VERYSILENT /SUPPRESSMSGBOXES /FORCECLOSEAPPLICATIONS
if !errorlevel! neq 0 (
echo Failed to uninstall Git from !locations[%%i]!
set "uninstall_error=1"
) else (
echo Successfully uninstalled Git from !locations[%%i]!
echo Cleaning up remaining files in !locations[%%i]!...
timeout /t 2 /nobreak >nul 2>nul
rd /s /q "!locations[%%i]!" >nul 2>nul
if !errorlevel! neq 0 (
echo Warning: Could not remove remaining files in !locations[%%i]!
set "cleanup_error=1"
) else (
echo Successfully removed remaining files in !locations[%%i]!
)
)
)
)
if defined uninstall_error (
echo One or more Git uninstallations failed.
timeout /t 5 /nobreak
exit /b 3
) else if defined cleanup_error (
echo Git was uninstalled but some cleanup operations failed.
echo Please check the listed locations and remove remaining files manually.
timeout /t 5 /nobreak
exit /b 4
) else (
echo All Git installations were successfully uninstalled and cleaned up.
timeout /t 5 /nobreak
exit /b 0
)