-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstallBase.ps1
More file actions
88 lines (75 loc) · 3.05 KB
/
uninstallBase.ps1
File metadata and controls
88 lines (75 loc) · 3.05 KB
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
# Script version
# Below variables are handled by external script that edits them.
$scriptVersion = "v1.1"
$APP_DISPLAYNAME = ""
$APP_BINARY = ""
$APP_OWNER = ""
$APP_FOLDER = ""
$APP_POST_UNINSTALL_MESSAGE = ""
# Define paths
$installPath = Join-Path $env:APPDATA "$APP_OWNER\$APP_FOLDER"
$isverPath = Join-Path $installPath "ISver.txt"
if (Test-Path $isverPath) {
$installedVersion = (Get-Content $isverPath -Raw).Trim()
} else {
$installedVersion = "unknown"
}
Write-Host "$APP_DISPLAYNAME ($installedVersion) uninstaller | IronShell uninstaller $scriptVersion" -ForegroundColor Cyan
# Check if already installed in user path
$binaryPath = Join-Path $installPath "$APP_BINARY"
Write-Host "Expected $APP_BINARY path: $binaryPath" -ForegroundColor Magenta
# Try to remove the binary (if it exists)
try {
if (Test-Path $binaryPath) {
Remove-Item $binaryPath -Force
Write-Host "Removed $APP_BINARY from $installPath" -ForegroundColor Green
} else {
Write-Host "$APP_BINARY not found in $installPath" -ForegroundColor Yellow
}
} catch {
Write-Host ("Failed to remove " + $APP_BINARY + ": " + $_) -ForegroundColor Red
}
# Try to remove ISver.txt (if it exists)
try {
if (Test-Path $isverPath) {
Remove-Item $isverPath -Force
Write-Host "Removed ISver.txt from $installPath" -ForegroundColor Green
} else {
Write-Host "ISver.txt not found in $installPath" -ForegroundColor Yellow
}
} catch {
Write-Host ("Failed to remove ISver.txt: " + $_) -ForegroundColor Red
}
# Try to remove the install directory if empty
try {
if (Test-Path $installPath) {
if ((Get-ChildItem -Path $installPath | Measure-Object).Count -eq 0) {
Remove-Item $installPath -Force
Write-Host "Removed empty install directory: $installPath" -ForegroundColor Green
} else {
Write-Host "Install directory not empty, not removed: $installPath" -ForegroundColor Yellow
}
} else {
Write-Host "$installPath does not exist, nothing to remove." -ForegroundColor Yellow
}
} catch {
Write-Host ("Failed to remove install directory: " + $_) -ForegroundColor Red
}
# Remove from user PATH if present
$userEnvPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if ($userEnvPath -like "*${installPath}*") {
$newPath = ((($userEnvPath -split ";") | Where-Object { $_ -ne $installPath }) -join ";")
[System.Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "Removed $installPath from user PATH" -ForegroundColor Green
} else {
Write-Host "$installPath not found in user PATH" -ForegroundColor Yellow
}
# Refresh PATH in current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User")
# Final message
Write-Host "Uninstallation complete! $APP_DISPLAYNAME has been removed." -ForegroundColor Green
if ($APP_POST_UNINSTALL_MESSAGE -ne "") {
Write-Host $APP_POST_UNINSTALL_MESSAGE -ForegroundColor Magenta
}
Write-Host "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")