major update
This commit is contained in:
+31
-27
@@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
Function Get-UninstallCodes ([string]$DisplayName) {
|
Function Get-UninstallCodes ([string]$DisplayName) {
|
||||||
Get-ChildItem -Path 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {
|
'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall' | ForEach-Object {
|
||||||
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -eq $DisplayName) ) {
|
Get-ChildItem -Path $_ -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
$str = (Get-ItemPropertyValue -Path $_.PSPath -Name 'UninstallString')
|
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -eq $DisplayName) ) {
|
||||||
$UninstallCodes += $str.Substring(($str.Length - 37),36)
|
$str = (Get-ItemPropertyValue -Path $_.PSPath -Name 'UninstallString')
|
||||||
|
$UninstallCodes.Add($str.Substring(($str.Length - 37),36)) | Out-Null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +13,7 @@ Function Get-UninstallCodes ([string]$DisplayName) {
|
|||||||
Function Get-ProductKeys ([string]$ProductName) {
|
Function Get-ProductKeys ([string]$ProductName) {
|
||||||
Get-ChildItem -Path 'HKCR:Installer\Products' | ForEach-Object {
|
Get-ChildItem -Path 'HKCR:Installer\Products' | ForEach-Object {
|
||||||
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -eq $ProductName) ) {
|
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -eq $ProductName) ) {
|
||||||
$ProductKeys += $_.PSPath.Substring(($_.PSPath.Length - 32))
|
$ProductKeys.Add($_.PSPath.Substring(($_.PSPath.Length - 32))) | Out-Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,31 +21,35 @@ Function Get-ProductKeys ([string]$ProductName) {
|
|||||||
Function Get-ServiceStatus ([string]$Name) { (Get-Service -Name $Name -ErrorAction SilentlyContinue).Status }
|
Function Get-ServiceStatus ([string]$Name) { (Get-Service -Name $Name -ErrorAction SilentlyContinue).Status }
|
||||||
|
|
||||||
Function Stop-RunningService ([string]$Name) {
|
Function Stop-RunningService ([string]$Name) {
|
||||||
If ( $(Get-ServiceStatus -Name $Name) -eq "Running" ) { Write-Output "Stopping ${Name} service" ; Stop-Service -Name $Name -Force }
|
If ( $(Get-ServiceStatus -Name $Name) -eq "Running" ) { Write-Output "Stopping : ${Name} service" ; Stop-Service -Name $Name -Force }
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Remove-StoppedService ([string]$Name) {
|
Function Remove-StoppedService ([string]$Name) {
|
||||||
If ( $(Get-ServiceStatus -Name $Name) -eq "Stopped" ) {
|
$s = (Get-ServiceStatus -Name $Name)
|
||||||
Write-Output "Deleting ${Name} service"
|
If ( $s ) {
|
||||||
Start-Process "sc.exe" -ArgumentList "delete ${Name}" -Wait
|
If ( $s -eq "Stopped" ) {
|
||||||
}
|
Write-Output "Deleting : ${Name} service"
|
||||||
|
Start-Process "sc.exe" -ArgumentList "delete ${Name}" -Wait
|
||||||
|
}
|
||||||
|
} Else { Write-Output "Not Found: ${Name} service" }
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Kill-Process ([string]$Name) {
|
Function Stop-RunningProcess ([string]$Name) {
|
||||||
$p = (Get-Process -Name $_ -ErrorAction SilentlyContinue)
|
$p = (Get-Process -Name $_ -ErrorAction SilentlyContinue)
|
||||||
If ( $p ) { Write-Output "Killing ${Name} process" ; $p | Stop-Process -Force }
|
If ( $p ) { Write-Output "Stopping : ${Name}.exe" ; $p | Stop-Process -Force }
|
||||||
|
Else { Write-Output "Not Found: ${Name}.exe is not running"}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Remove-Path ([string]$Path) {
|
Function Remove-Path ([string]$Path) {
|
||||||
If ( Test-Path $Path ) {
|
If ( Test-Path $Path ) {
|
||||||
Write-Output "Deleting ${Path}"
|
Write-Output "Deleting : ${Path}"
|
||||||
Remove-Item -Path $Path -Force
|
Remove-Item $Path -Recurse -Force
|
||||||
} Else { Write-Output "ERROR: Path not found: ${Path}" }
|
} Else { Write-Output "Not Found: ${Path}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-AllExeFiles ([string]$Path) {
|
Function Get-AllExeFiles ([string]$Path) {
|
||||||
If ( Test-Path $Path ) {
|
If ( Test-Path $Path ) {
|
||||||
Get-ChildItem -Path $Path -Filter *.exe -Recurse | ForEach-Object { $ExeFiles =+ $_.BaseName }
|
Get-ChildItem -Path $Path -Filter *.exe -Recurse | ForEach-Object { $ExeFiles.Add($_.BaseName) | Out-Null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,11 +61,11 @@ New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
|
|||||||
#######
|
#######
|
||||||
|
|
||||||
# Get MSI package codes from the uninstall key
|
# Get MSI package codes from the uninstall key
|
||||||
$UninstallCodes = @()
|
$UninstallCodes = New-Object System.Collections.ArrayList
|
||||||
'AteraAgent', 'Splashtop for RMM', 'Splashtop Streamer' | ForEach-Object { Get-UninstallCodes -DisplayName $_ }
|
'AteraAgent', 'Splashtop for RMM', 'Splashtop Streamer' | ForEach-Object { Get-UninstallCodes -DisplayName $_ }
|
||||||
|
|
||||||
# Get product keys from the list of installed products
|
# Get product keys from the list of installed products
|
||||||
$ProductKeys = @()
|
$ProductKeys = New-Object System.Collections.ArrayList
|
||||||
'AteraAgent', 'Splashtop for RMM', 'Splashtop Streamer' | ForEach-Object { Get-ProductKeys -ProductName $_ }
|
'AteraAgent', 'Splashtop for RMM', 'Splashtop Streamer' | ForEach-Object { Get-ProductKeys -ProductName $_ }
|
||||||
|
|
||||||
# Define all the directories we'll need to cleanup at the end of this script
|
# Define all the directories we'll need to cleanup at the end of this script
|
||||||
@@ -73,8 +79,8 @@ $Directories = @(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Get all possible relevant exe files so we can make sure they're closed later on
|
# Get all possible relevant exe files so we can make sure they're closed later on
|
||||||
$ExeFiles = @()
|
$ExeFiles = New-Object System.Collections.ArrayList
|
||||||
$Directories | ForEach-Object { Get-AllExeFiles -Path $_ }
|
"${Env:ProgramFiles}\ATERA Networks" | ForEach-Object { Get-AllExeFiles -Path $_ }
|
||||||
|
|
||||||
# Define a list of services we need to stop and delete (if necessary)
|
# Define a list of services we need to stop and delete (if necessary)
|
||||||
$ServiceList = @(
|
$ServiceList = @(
|
||||||
@@ -95,21 +101,18 @@ $RegistryKeys = @(
|
|||||||
#######
|
#######
|
||||||
|
|
||||||
# Uninstall each MSI package code in $UninstallCodes
|
# Uninstall each MSI package code in $UninstallCodes
|
||||||
$UninstallCodes | ForEach-Object { Write-Output "Uninstalling product code: ${_}" ; Start-Process "msiexec.exe" -ArgumentList "/X{${_}}" -Wait }
|
$UninstallCodes | ForEach-Object { Write-Output "Uninstall: ${_}" ; Start-Process "msiexec.exe" -ArgumentList "/X{${_}} /qn" -Wait }
|
||||||
|
|
||||||
# Stop services if they're still running
|
# Stop services if they're still running
|
||||||
$ServiceList | ForEach-Object { Stop-RunningService -Name $_ }
|
$ServiceList | ForEach-Object { Stop-RunningService -Name $_ }
|
||||||
|
|
||||||
# Kill all relevant processes that may still be running
|
# Terminate all relevant processes that may still be running
|
||||||
$ExeFiles += 'reg'
|
$ExeFiles.Add('reg') | Out-Null
|
||||||
$ExeFiles | ForEach-Object { Kill-Process $_ }
|
$ExeFiles | ForEach-Object { Stop-RunningProcess $_ }
|
||||||
|
|
||||||
# Delete services if they're still present
|
# Delete services if they're still present
|
||||||
$ServiceList | ForEach-Object { Remove-StoppedService -Name $_ }
|
$ServiceList | ForEach-Object { Remove-StoppedService -Name $_ }
|
||||||
|
|
||||||
# This seems unnecessary, but it's included in Atera's official uninstall script so I included it here but left it commented out
|
|
||||||
#Start-Sleep -Seconds 4
|
|
||||||
|
|
||||||
# Delete products from MSI installer registry
|
# Delete products from MSI installer registry
|
||||||
$ProductKeys | ForEach-Object { Remove-Path -Path "HKCR:Installer\Products\${_}" }
|
$ProductKeys | ForEach-Object { Remove-Path -Path "HKCR:Installer\Products\${_}" }
|
||||||
|
|
||||||
@@ -120,6 +123,7 @@ Remove-PSDrive -Name HKCR
|
|||||||
$RegistryKeys | ForEach-Object { Remove-Path -Path $_ }
|
$RegistryKeys | ForEach-Object { Remove-Path -Path $_ }
|
||||||
|
|
||||||
# Delete remaining directories
|
# Delete remaining directories
|
||||||
|
#Write-Host "Waiting for file locks to be freed" ; Start-Sleep -Seconds 4
|
||||||
$Directories | ForEach-Object { Remove-Path -Path $_ }
|
$Directories | ForEach-Object { Remove-Path -Path $_ }
|
||||||
|
|
||||||
# Atera's original script also deleted the following directories and registry keys
|
# Atera's original script also deleted the following directories and registry keys
|
||||||
|
|||||||
Reference in New Issue
Block a user