Files

66 lines
2.4 KiB
PowerShell
Raw Permalink Normal View History

2022-08-09 15:10:18 -04:00
# List all possible TeamViewer installation paths here.
2019-11-11 19:22:39 -05:00
$UninstallerPaths = @(
"${Env:ProgramFiles}\TeamViewer\Version6\uninstall.exe",
"${Env:ProgramFiles(x86)}\TeamViewer\Version6\uninstall.exe",
"${Env:ProgramFiles}\TeamViewer\Version7\uninstall.exe",
"${Env:ProgramFiles(x86)}\TeamViewer\Version7\uninstall.exe",
"${Env:ProgramFiles}\TeamViewer\Version8\uninstall.exe",
"${Env:ProgramFiles(x86)}\TeamViewer\Version8\uninstall.exe",
"${Env:ProgramFiles}\TeamViewer\Version9\uninstall.exe",
"${Env:ProgramFiles(x86)}\TeamViewer\Version9\uninstall.exe",
"${Env:ProgramFiles}\TeamViewer\uninstall.exe",
"${Env:ProgramFiles(x86)}\TeamViewer\uninstall.exe"
"${Env:ProgramFiles}\Take Control Viewer\uninstall.exe",
"${Env:ProgramFiles(x86)}\Take Control Viewer\uninstall.exe"
)
2022-08-09 15:10:18 -04:00
# List all known registry keys
2019-11-11 19:22:39 -05:00
$RegKeys = @(
"HKLM\SOFTWARE\TeamViewer",
"HKLM\SOFTWARE\WOW6432Node\TeamViewer",
"HKLM\SOFTWARE\WOW6432Node\TVInstallTemp",
"HKCU\SOFTWARE\TeamViewer",
"HKCU\SOFTWARE\Wow6432Node\TeamViewer"
)
2022-08-09 15:10:18 -04:00
# Find the most likely path to the TeamViewer uninstaller
2020-05-22 14:35:46 -04:00
If ( Test-Path "${Env:ProgramFiles(x86)}" )
{
2019-11-11 19:22:39 -05:00
$INSTALLDIR = $(Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\TeamViewer").InstallationDirectory
2020-05-22 14:35:46 -04:00
}
Else
{
2019-11-11 19:22:39 -05:00
$INSTALLDIR = $(Get-ItemProperty -Path "HKLM:\SOFTWARE\TeamViewer").InstallationDirectory
}
2022-08-09 15:10:18 -04:00
# Kill all running instances of TeamViewer
2025-04-11 17:22:26 -04:00
Get-Process | Where-Object { $_.Name -like "*TeamViewer*" } | Stop-Process -Force
2019-11-11 19:22:39 -05:00
2020-05-22 14:35:46 -04:00
If ( Test-Path "${INSTALLDIR}\uninstall.exe" )
{ Start-Process "${INSTALLDIR}\uninstall.exe" -ArgumentList "/S" -Wait }
2019-11-11 19:22:39 -05:00
2022-08-09 15:10:18 -04:00
# Loop through each path in $UninstallerPaths and test if each one exists.
# If a path exists, silently run the uninstaller and then delete the directory.
2020-05-22 14:35:46 -04:00
Foreach ($uninstaller in $UninstallerPaths)
{
If ( Test-Path "${uninstaller}" )
{
2022-08-09 15:10:18 -04:00
# Run the uninstaller
2020-05-22 14:35:46 -04:00
Start-Process "${uninstaller}" -ArgumentList "/S" -Wait
2022-08-09 15:10:18 -04:00
# Remove the directory
2020-05-22 14:35:46 -04:00
$dirname = $(Get-Item $uninstaller).Directory.FullName
Remove-Item "${dirname}" -Recurse -ErrorAction SilentlyContinue
}
2019-11-11 19:22:39 -05:00
}
2022-08-09 15:10:18 -04:00
# Remove each registry key in $RegKeys
2020-05-22 14:35:46 -04:00
Foreach ($key in $RegKeys)
{
If ( Test-Path $key ) { Remove-Item $key -Recurse }
2019-11-11 19:22:39 -05:00
}
2022-08-09 15:10:18 -04:00
# Remove the TeamViewer service
2020-05-22 14:35:46 -04:00
Start-Process "sc.exe" -ArgumentList "delete TeamViewer" -Wait
Start-Process "sc.exe" -ArgumentList "delete TeamViewer_Service" -Wait