52 lines
2.3 KiB
PowerShell
52 lines
2.3 KiB
PowerShell
## List all possible TeamViewer installation paths here.
|
|||
|
|
$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"
|
||
|
|
)
|
||
|
|
|
||
|
|
## List all known registry keys
|
||
|
|
$RegKeys = @(
|
||
|
|
"HKLM\SOFTWARE\TeamViewer",
|
||
|
|
"HKLM\SOFTWARE\WOW6432Node\TeamViewer",
|
||
|
|
"HKLM\SOFTWARE\WOW6432Node\TVInstallTemp",
|
||
|
|
"HKCU\SOFTWARE\TeamViewer",
|
||
|
|
"HKCU\SOFTWARE\Wow6432Node\TeamViewer"
|
||
|
|
)
|
||
|
|
|
||
|
|
## Find the most likely path to the TeamViewer uninstaller
|
||
|
|
If ( Test-Path "${Env:ProgramFiles(x86)}" ) {
|
||
|
|
$INSTALLDIR = $(Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\TeamViewer").InstallationDirectory
|
||
|
|
} Else {
|
||
|
|
$INSTALLDIR = $(Get-ItemProperty -Path "HKLM:\SOFTWARE\TeamViewer").InstallationDirectory
|
||
|
|
}
|
||
|
|
|
||
|
|
## Kill all running instances of TeamViewer
|
||
|
|
Get-Process | Where { $_.Name -like "*TeamViewer*" }
|
||
|
|
|
||
|
|
If ( Test-Path "${INSTALLDIR}\uninstall.exe" ) { Start-Process "${INSTALLDIR}\uninstall.exe" -ArgumentList "/S" -Wait }
|
||
|
|
|
||
|
|
## 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.
|
||
|
|
Foreach ($uninstaller in $UninstallerPaths) {
|
||
|
|
if ( Test-Path "${uninstaller}" ) { Start-Process "${uninstaller}" -ArgumentList "/S" -Wait }
|
||
|
|
if ( Test-Path "${(Get-Item $uninstaller).Directory.FullName}" ) { Remove-Item "${(Get-Item $uninstaller).Directory.FullName}" -Recurse }
|
||
|
|
}
|
||
|
|
|
||
|
|
## Remove each registry key in $RegKeys
|
||
|
|
Foreach ($key in $RegKeys) {
|
||
|
|
if ( Test-Path $key ) { Remove-Item $key -Recurse }
|
||
|
|
}
|
||
|
|
|
||
|
|
## Remove the TeamViewer service
|
||
|
|
Start-Process "sc.exe" -ArgumentList "delete TeamViewer"
|
||
|
|
Start-Process "sc.exe" -ArgumentList "delete TeamViewer_Service"
|