Skip to content

Instantly share code, notes, and snippets.

@supermarsx
Created August 29, 2026 20:39
Show Gist options
  • Select an option

  • Save supermarsx/eb22f16061beadf763c0a20689a02245 to your computer and use it in GitHub Desktop.

Select an option

Save supermarsx/eb22f16061beadf763c0a20689a02245 to your computer and use it in GitHub Desktop.
Reset Anydesk data
<#
.SYNOPSIS
Factory-reset AnyDesk on Windows without uninstalling it.
.DESCRIPTION
- Self-elevates
- Finds standard/custom AnyDesk installations
- Removes Unattended Access password and license where possible
- Stops AnyDesk processes/services
- Deletes machine configuration
- Deletes AnyDesk configuration from every local user profile
- Removes leftover AnyDesk application registry configuration
- Restarts installed AnyDesk services
IMPORTANT:
This intentionally destroys the existing AnyDesk:
- ID
- Alias
- License registration
- Unattended Access password
- Access-control settings
- Account/session configuration
- History / thumbnails / local preferences
It DOES NOT uninstall AnyDesk.
#>
[CmdletBinding()]
param(
[switch]$NoRegistryCleanup
)
$ErrorActionPreference = 'SilentlyContinue'
# ---------------------------------------------------------------------------
# Elevate
# ---------------------------------------------------------------------------
$IsAdmin = ([Security.Principal.WindowsPrincipal]::new(
[Security.Principal.WindowsIdentity]::GetCurrent()
)).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $IsAdmin) {
Write-Host "[!] Administrator privileges required. Elevating..." -ForegroundColor Yellow
# Relaunch using the same PowerShell edition currently running.
# PS7 -> pwsh.exe
# PS5 -> powershell.exe
$PowerShellExe = (Get-Process -Id $PID).Path
$arguments = @(
'-NoProfile'
'-ExecutionPolicy'
'Bypass'
'-File'
"`"$PSCommandPath`""
)
if ($NoRegistryCleanup) {
$arguments += '-NoRegistryCleanup'
}
Start-Process -FilePath $PowerShellExe -Verb RunAs -ArgumentList $arguments
exit
}
Clear-Host
Write-Host ""
Write-Host "=========================================================" -ForegroundColor Cyan
Write-Host " ANYDESK FACTORY RESET " -ForegroundColor Cyan
Write-Host "=========================================================" -ForegroundColor Cyan
Write-Host ""
# ---------------------------------------------------------------------------
# Discover AnyDesk executables
# ---------------------------------------------------------------------------
Write-Host "[*] Discovering AnyDesk installations..." -ForegroundColor Cyan
$AnyDeskExecutables = @()
$searchRoots = @(
"$env:ProgramFiles\AnyDesk",
"${env:ProgramFiles(x86)}\AnyDesk"
)
# Standard installations
foreach ($root in $searchRoots) {
if (Test-Path $root) {
$AnyDeskExecutables += Get-ChildItem `
-Path $root `
-Filter '*.exe' `
-File `
-Recurse
}
}
# Custom AnyDesk clients, e.g. AnyDesk-company / AnyDesk-ad_xxxxx
foreach ($base in @($env:ProgramFiles, ${env:ProgramFiles(x86)})) {
if (-not $base) {
continue
}
Get-ChildItem $base -Directory |
Where-Object {
$_.Name -like 'AnyDesk*'
} |
ForEach-Object {
$AnyDeskExecutables += Get-ChildItem `
$_.FullName `
-Filter '*.exe' `
-File `
-Recurse
}
}
$AnyDeskExecutables = $AnyDeskExecutables |
Where-Object {
$_.Name -like 'AnyDesk*.exe'
} |
Sort-Object FullName -Unique
foreach ($exe in $AnyDeskExecutables) {
Write-Host " Found: $($exe.FullName)"
}
# ---------------------------------------------------------------------------
# Obtain old IDs where possible
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Existing AnyDesk identity:" -ForegroundColor Cyan
foreach ($exe in $AnyDeskExecutables) {
try {
$id = & $exe.FullName --get-id 2>$null
if ($id) {
Write-Host " ID: $id" -ForegroundColor Yellow
}
$alias = & $exe.FullName --get-alias 2>$null
if ($alias) {
Write-Host " Alias: $alias" -ForegroundColor Yellow
}
}
catch {}
}
# ---------------------------------------------------------------------------
# Remove password / license through official CLI first
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Removing AnyDesk credentials..." -ForegroundColor Cyan
foreach ($exe in $AnyDeskExecutables) {
Write-Host " $($exe.Name)"
try {
& $exe.FullName --remove-password 2>$null | Out-Null
}
catch {}
try {
& $exe.FullName --remove-license 2>$null | Out-Null
}
catch {}
}
# AnyDesk officially exposes both --remove-password and --remove-license.
# The filesystem deletion below is still performed afterwards.
# ---------------------------------------------------------------------------
# Stop AnyDesk services
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Stopping AnyDesk services..." -ForegroundColor Cyan
$AnyDeskServices = Get-Service |
Where-Object {
$_.Name -like '*AnyDesk*' -or
$_.DisplayName -like '*AnyDesk*'
}
foreach ($service in $AnyDeskServices) {
Write-Host " Stopping: $($service.Name)"
Stop-Service `
-Name $service.Name `
-Force `
-ErrorAction SilentlyContinue
}
# ---------------------------------------------------------------------------
# Kill AnyDesk processes, including custom clients
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Killing remaining AnyDesk processes..." -ForegroundColor Cyan
Get-CimInstance Win32_Process |
Where-Object {
($_.Name -like '*AnyDesk*') -or
($_.ExecutablePath -like '*\AnyDesk*\*') -or
($_.ExecutablePath -like '*\AnyDesk-*\*')
} |
ForEach-Object {
Write-Host " Killing PID $($_.ProcessId): $($_.Name)"
Stop-Process `
-Id $_.ProcessId `
-Force `
-ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 2
# ---------------------------------------------------------------------------
# Machine-wide configuration
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Removing machine-wide configuration..." -ForegroundColor Cyan
$machinePaths = @(
"$env:ProgramData\AnyDesk"
)
foreach ($path in $machinePaths) {
if (Test-Path $path) {
Write-Host " DELETE $path" -ForegroundColor Red
Remove-Item `
-LiteralPath $path `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
# ---------------------------------------------------------------------------
# Every local Windows user
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Removing per-user AnyDesk configuration..." -ForegroundColor Cyan
$Profiles = Get-CimInstance Win32_UserProfile |
Where-Object {
-not $_.Special -and
$_.LocalPath -and
(Test-Path $_.LocalPath)
}
foreach ($profile in $Profiles) {
$username = Split-Path $profile.LocalPath -Leaf
$paths = @(
"$($profile.LocalPath)\AppData\Roaming\AnyDesk",
"$($profile.LocalPath)\AppData\Local\AnyDesk"
)
foreach ($path in $paths) {
if (Test-Path $path) {
Write-Host " [$username] DELETE $path" -ForegroundColor Red
Remove-Item `
-LiteralPath $path `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
}
# ---------------------------------------------------------------------------
# Registry configuration
# ---------------------------------------------------------------------------
if (-not $NoRegistryCleanup) {
Write-Host ""
Write-Host "[*] Cleaning AnyDesk application registry keys..." -ForegroundColor Cyan
#
# DO NOT touch:
#
# HKLM:\SYSTEM\CurrentControlSet\Services\AnyDesk
# HKLM:\...\Uninstall\AnyDesk
#
# Those belong to the installation/service itself.
#
$machineRegKeys = @(
'HKLM:\SOFTWARE\AnyDesk',
'HKLM:\SOFTWARE\WOW6432Node\AnyDesk'
)
foreach ($key in $machineRegKeys) {
if (Test-Path $key) {
Write-Host " DELETE $key"
Remove-Item `
$key `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
# Clean AnyDesk software settings from loaded users
Get-ChildItem Registry::HKEY_USERS |
Where-Object {
$_.PSChildName -match '^S-1-5-21-'
} |
ForEach-Object {
$sid = $_.PSChildName
$key = "Registry::HKEY_USERS\$sid\Software\AnyDesk"
if (Test-Path $key) {
Write-Host " DELETE HKU\$sid\Software\AnyDesk"
Remove-Item `
$key `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
}
# ---------------------------------------------------------------------------
# Verify deletion
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Verifying reset..." -ForegroundColor Cyan
$leftovers = @()
if (Test-Path "$env:ProgramData\AnyDesk") {
$leftovers += "$env:ProgramData\AnyDesk"
}
foreach ($profile in $Profiles) {
$path = "$($profile.LocalPath)\AppData\Roaming\AnyDesk"
if (Test-Path $path) {
$leftovers += $path
}
}
if ($leftovers.Count -eq 0) {
Write-Host " Configuration successfully removed." -ForegroundColor Green
}
else {
Write-Host " Some paths could not be deleted:" -ForegroundColor Yellow
foreach ($item in $leftovers) {
Write-Host " $item"
}
}
# ---------------------------------------------------------------------------
# Restart installed AnyDesk service
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] Starting AnyDesk services..." -ForegroundColor Cyan
foreach ($service in $AnyDeskServices) {
Start-Service `
-Name $service.Name `
-ErrorAction SilentlyContinue
Write-Host " Started: $($service.Name)"
}
Start-Sleep -Seconds 4
# ---------------------------------------------------------------------------
# New identity
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "[*] New AnyDesk identity:" -ForegroundColor Cyan
foreach ($exe in $AnyDeskExecutables) {
try {
$id = & $exe.FullName --get-id 2>$null
if ($id) {
Write-Host ""
Write-Host " NEW ID: $id" -ForegroundColor Green
}
}
catch {}
}
Write-Host ""
Write-Host "=========================================================" -ForegroundColor Green
Write-Host " RESET COMPLETE " -ForegroundColor Green
Write-Host "=========================================================" -ForegroundColor Green
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment