Skip to content

Instantly share code, notes, and snippets.

@djhohnstein
Forked from mgeeky/Cleanup-ClickOnce.ps1
Created June 27, 2023 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djhohnstein/1c125303cc7a9aa4d0359eef7904903e to your computer and use it in GitHub Desktop.
Save djhohnstein/1c125303cc7a9aa4d0359eef7904903e to your computer and use it in GitHub Desktop.
Cleanup-ClickOnce.ps1 - Simple Powershell script that removes ClickOnce deployments entirely from file system and registry.
#
# Usage:
# PS> . .\Cleanup-ClickOnce.ps1
# PS> Cleanup-ClickOnce -Name MyAppName
#
# Other than that you might also try using these commands:
# PS> rundll32 dfshim.dll,ShArpMaintain C:\Path\To\ClickOnce.application
# PS> rundll32 dfshim.dll CleanOnlineAppCache
#
function Cleanup-ClickOnce($Name) {
if ($Name.Length -gt 7) {
$Name = $Name.Substring(0, 4) + "\."
}
$rex = $Name + "\..+"
Write-Host "`nCleaning ClickOnce leftovers: $rex `n" -ForegroundColor Yellow
Get-ChildItem -Recurse "HKCU:\Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0" -EA SilentlyContinue | ForEach-Object {
If ($_ -match $rex) {
Write-Host "[+] Cleaning: $($_.Name)" -ForegroundColor Green
Remove-Item -Force -Recurse "Registry::$_" -EA SilentlyContinue | Out-Null
}
}
$Paths = @(
"$env:Localappdata\Apps\2.0"
"$env:Localappdata\Deployment"
"$env:Localappdata\Microsoft\Windows\INetCache\IE"
"$env:Temp\Deployment"
)
foreach ($Path in $Paths) {
Get-ChildItem -Recurse $Path | ForEach-Object {
If ($_ -match $rex) {
Write-Host "[+] Cleaning: $($_.FullName)" -ForegroundColor Green
Remove-Item -Force -Recurse $_.FullName
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment