Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstaller Known Issues #3

Open
tboy1337 opened this issue Oct 22, 2024 · 1 comment
Open

Uninstaller Known Issues #3

tboy1337 opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@tboy1337
Copy link
Owner

  • Uninstaller fails to find Git if the script is run from a non-administrator Windows user account and Git is installed in user directory e.g. %LOCALAPPDATA%\Programs\Git.
@tboy1337
Copy link
Owner Author

tboy1337 commented Oct 22, 2024

Possibly fixed by the below code, this way you wouldn't be able to run the uninstaller from another batch file or would require user interaction on the target machine.

@echo off
setlocal enabledelayedexpansion

set "userLocalAppData=%LOCALAPPDATA%"
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]=%userLocalAppData%\Programs\Git"
set "found_installations=0"

    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params= %*
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

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 7
)

for /L %%i in (0,1,4) do (
    if exist "!locations[%%i]!\unins*.exe" (
        echo Found Git installation in !locations[%%i]! with uninstaller !found_uninstaller!
        
        echo Terminating running Git processes...
        taskkill /F /IM "bash.exe" 2>nul
        taskkill /F /IM "putty.exe" 2>nul
        taskkill /F /IM "puttytel.exe" 2>nul
        taskkill /F /IM "puttygen.exe" 2>nul
        taskkill /F /IM "pageant.exe" 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
            
            rd /s /q "!locations[%%i]!" 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 5
) 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 6
) else (
    echo All Git installations were successfully uninstalled and cleaned up.
    timeout /t 5 /nobreak
    exit /b 0
)

@tboy1337 tboy1337 added the bug Something isn't working label Oct 22, 2024
@tboy1337 tboy1337 self-assigned this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant