-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstall-Shortcuts.ps1
More file actions
63 lines (53 loc) · 2.27 KB
/
Uninstall-Shortcuts.ps1
File metadata and controls
63 lines (53 loc) · 2.27 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
#Requires -Version 5.1
<#
.SYNOPSIS
Removes all sandbox-related configuration and files from the installation folder.
.DESCRIPTION
-None-
.PARAMETER InstallDirectory
An existing directory where this script should remove its runtime dependencies from.
.EXAMPLE
Uninstall-Shortcuts -InstallDirectory 'C:\Program Files\OpenInContainer'
.LINK
https://github.com/Bert-Proesmans/WindowsSandboxShortcuts
.NOTES
Author: Bert Proesmans
#>
param (
[Parameter(Mandatory = $true)]
[ValidateScript({
if (-Not ($_ | Test-Path) ) {
throw "Folder does not exist."
}
if (-Not ($_ | Test-Path -PathType Container) ) {
throw "The InstallDirectory argument must be a directory. File paths are not allowed."
}
return $true
})]
[string]$InstallDirectory
)
# WARN; Variable types are sticky, so we manually override the type once
[System.Management.Automation.PathInfo]$InstallDirectory = Resolve-Path $InstallDirectory
$FilesToRemove = @(
$InstallDirectory | Join-Path -ChildPath 'Start-Container.ps1'
)
Remove-Item -Path $FilesToRemove -Force | Out-Null
Function Remove-QuickItem {
param (
$FileCommonName,
$FileExtension,
$ItemLabel = "Run $FileExtension in a sandbox",
[string[]]$CustomPath = @()
)
$ClassesPath = (@("Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Classes", $FileCommonName) + $CustomPath) -join '\'
$QuickItemPath = $ClassesPath, 'Shell', $ItemLabel -join '\'
Remove-Item -Path $QuickItemPath -Recurse -Force | Out-Null
}
Remove-QuickItem -FileCommonName 'Directory' -ItemLabel "Open folder in a sandbox"
Remove-QuickItem -FileCommonName 'Directory' -CustomPath "Background" -ItemLabel "Open folder in a sandbox"
Remove-QuickItem -FileCommonName 'exefile' -FileExtension 'EXE'
Remove-QuickItem -FileCommonName 'Msi.Package' -FileExtension 'MSI'
Remove-QuickItem -CustomPath 'SystemFileAssociations', '.pdf' -FileExtension 'PDF'
Remove-QuickItem -CustomPath 'SystemFileAssociations', '.ps1' -ItemLabel "Open script in a sandbox"
Remove-QuickItem -CustomPath 'SystemFileAssociations', '.cmd' -ItemLabel "Open script in a sandbox"
Remove-QuickItem -CustomPath 'SystemFileAssociations', '.bat' -ItemLabel "Open script in a sandbox"