-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.ps1
More file actions
68 lines (56 loc) · 2.3 KB
/
uninstall.ps1
File metadata and controls
68 lines (56 loc) · 2.3 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
# =========================================================
# WinHtop PowerShell Uninstaller (v0.5)
# Replicates Winhtop-installer.iss behavior
# =========================================================
$AppName = "WinHtop"
$InstallDir = Join-Path $env:LOCALAPPDATA "Programs\$AppName"
Write-Host "Uninstalling $AppName..." -ForegroundColor Cyan
# 1. Remove Shortcuts
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$StartMenuDir = Join-Path ([Environment]::GetFolderPath("Programs")) $AppName
$Shortcuts = @(
(Join-Path $DesktopPath "$AppName.lnk"),
(Join-Path $StartMenuDir "$AppName.lnk")
)
foreach ($Path in $Shortcuts) {
if (Test-Path $Path) {
Remove-Item $Path -Force
Write-Host "Removed shortcut: $Path" -ForegroundColor Yellow
}
}
# Remove Start Menu directory if empty
if (Test-Path $StartMenuDir) {
$Files = Get-ChildItem -Path $StartMenuDir
if ($Files.Count -eq 0) {
Remove-Item $StartMenuDir -Force
Write-Host "Removed Start Menu directory: $StartMenuDir" -ForegroundColor Yellow
}
}
# 2. Remove from User PATH
Write-Host "Removing from User PATH..." -ForegroundColor Cyan
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
$PathParts = $UserPath -split ";" | Where-Object { $_ -ne "" -and $_ -ne $InstallDir }
$NewPath = $PathParts -join ";"
[Environment]::SetEnvironmentVariable("Path", $NewPath, "User")
# Refresh environment (WM_SETTINGCHANGE)
$Signature = @'
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(
IntPtr hWnd, uint Msg, IntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out IntPtr lpdwResult);
'@
try {
$Win32 = Add-Type -MemberDefinition $Signature -Name "Win32Environment" -Namespace "Win32" -PassThru -ErrorAction SilentlyContinue
if ($Win32) {
$result = [IntPtr]::Zero
$Win32::SendMessageTimeout([IntPtr]0xffff, 0x001A, [IntPtr]::Zero, "Environment", 0x0002, 5000, [ref]$result) | Out-Null
}
}
catch {}
Write-Host "Removed $AppName from User PATH." -ForegroundColor Green
# 3. Remove Files
if (Test-Path $InstallDir) {
Remove-Item $InstallDir -Recurse -Force
Write-Host "Removed installation files from $InstallDir" -ForegroundColor Yellow
}
Write-Host "`nUninstallation Complete." -ForegroundColor Green