-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.ps1
More file actions
57 lines (46 loc) · 2.67 KB
/
uninstall.ps1
File metadata and controls
57 lines (46 loc) · 2.67 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
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[string]$InstallDir = (Join-Path $env:LOCALAPPDATA "Programs\MiniTaskbar"),
[string]$RunKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run",
[switch]$SkipRestore
)
$ErrorActionPreference = "Stop"
$programsRoot = [System.IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA "Programs"))
$defaultInstallDir = [System.IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA "Programs\MiniTaskbar"))
$resolvedInstallDir = [System.IO.Path]::GetFullPath($InstallDir)
$temporaryRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath()).TrimEnd([System.IO.Path]::DirectorySeparatorChar)
$temporaryTestPrefix = Join-Path $temporaryRoot "MiniTaskbarInstallTests-"
$temporaryTestPattern = '^' + [System.Text.RegularExpressions.Regex]::Escape($temporaryTestPrefix) + '[0-9a-f]{32}\\install$'
$isDefaultInstallDir = [System.String]::Equals($resolvedInstallDir, $defaultInstallDir, [System.StringComparison]::OrdinalIgnoreCase)
$isTemporaryInstallDir = $resolvedInstallDir -match $temporaryTestPattern
$defaultRunKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$isDefaultRunKey = [System.String]::Equals($RunKey, $defaultRunKey, [System.StringComparison]::OrdinalIgnoreCase)
$isTemporaryRunKey = $RunKey -match '^HKCU:\\Software\\MiniTaskbarTests\\[0-9a-f]{32}$'
$installedExe = Join-Path $resolvedInstallDir "mini_taskbar.exe"
$applied = $false
if (-not (($isDefaultInstallDir -and $isDefaultRunKey) -or ($isTemporaryInstallDir -and $isTemporaryRunKey))) {
throw "Refusing to uninstall an unexpected target: $resolvedInstallDir with $RunKey"
}
if ($SkipRestore -and -not $isTemporaryInstallDir) {
throw "SkipRestore is allowed only for temporary test installations."
}
if (-not ($isTemporaryInstallDir -or $resolvedInstallDir.StartsWith($programsRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase))) {
throw "Refusing to remove an unexpected directory: $resolvedInstallDir"
}
if ($PSCmdlet.ShouldProcess($resolvedInstallDir, "Unregister, restore and remove MiniTaskbar")) {
Remove-ItemProperty -LiteralPath $RunKey -Name "MiniTaskbar" -ErrorAction SilentlyContinue
Get-Process -Name "mini_taskbar" -ErrorAction SilentlyContinue |
Where-Object { $_.Path -eq $installedExe } |
Stop-Process -Force -ErrorAction SilentlyContinue
if ((Test-Path -LiteralPath $installedExe) -and -not $SkipRestore) {
& $installedExe --restore
}
if (Test-Path -LiteralPath $resolvedInstallDir) {
Remove-Item -LiteralPath $resolvedInstallDir -Recurse -Force
}
$applied = $true
}
[pscustomobject]@{
InstallDir = $resolvedInstallDir
Applied = $applied
}