Cannot Uninstall Automox Agent
Has an Agent file been corrupted, the amagent.exe been deleted, or are you trying to clean up installs of the Agent in general? There's actually a simple solution.
Steps to resolution
- Use the script attached to this article! It's the CleanUp-AxAgent script. If you're having issues downloading the attachment, there is a text-based version below.
- Note: This is a PowerShell script that needs to be run with elevated permissions!
function CleanUp-AxAgent
{
<#
.SYNOPSIS
Comprehensive removal of any remnants of the Automox Agent left behind from a broken state.
Use this if reinstallation fails.
.DESCRIPTION
.NOTES
This fix only applies to the local device
Released: 2019-08-15
Author: Automox Support
.EXAMPLE
Repair-Axservice
.LINK
http://www.automox.com
#>
#region uninstall
# Uninstall with MSI method if found present
# Define Values
$OSArch = (Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture
# Set agent path accordingly to OS Architectire
if ($OSArch -match "64-bit")
{
$installPath = "${env:ProgramFiles(x86)}\Automox"
}
else
{
$installPath = "${env:ProgramFiles}\Automox"
}
$uninstReg = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
$appName = 'Automox Agent'
$logPath = "C:\ProgramData\amagent"
#Get all entries that match our criteria. DisplayName matches $appname
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object { ($_.DisplayName -match $appName) })
if ($installed)
{
Write-Output "Agent still installed`nRemoving...`n"
$process = Start-Process msiexec.exe -ArgumentList "/x $( $installed.PSChildName ) /qn REBOOT=ReallySuppress" -Wait -PassThru
Write-Output "Uninstall Completed with Exit Code: $( $process.ExitCode )`n`nProceeding with additional cleanup steps"
}
else
{
Write-Warning "Automox Agent isn't properly installed.`nProceeding with additional cleanup steps"
}
#endregion
#region cleanup
# Determine if the Automox Agent process is currently running
$agentProcess = Get-Process amagent -ErrorAction SilentlyContinue
# If Agent is running, force it to stop
if ($null -ne $agentProcess)
{
Try
{
Write-Output "Stopping amagent.exe process"
Stop-Process $agentProcess -Force -ErrorAction Stop
}
Catch
{
Write-Error "Unable to stop Automox Agent process.`nFiles may be left behind in C:\ProgramData\amagent\ folder";
}
}
# Determine 64 vs 32-bit OS Architecture
if (Test-Path $installPath)
{
$installPath | Remove-Item -Recurse -Force
}
# Make sure no msiexec processes are lingering from our uninstall attempt
# then remove C:\ProgramData\amagent\ directory
Get-Process msiexe[c] | Stop-Process -Force
if (Test-Path $logPath)
{
$logPath | Remove-Item -Recurse -Force
}
# CleanUp registry settings that could potentially be left behind.
New-PSDrive -PSProvider Registry -Name HKCR -Root HKEY_CLASSES_ROOT -ErrorAction SilentlyContinue | Out-Null
$rootKey = (Get-ChildItem "HKCR:\Installer\Products\" -Recurse -ErrorAction SilentlyContinue) | Get-ItemProperty | Where-Object { $_.ProductName -match "Automox Agent" }
$hklmKey = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\" -Recurse -ErrorAction SilentlyContinue) | Get-ItemProperty | Where-Object { $_.DisplayName -match "Automox Agent" }
$otherKeys = @("HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Application\amagent", "SYSTEM\CurrentControlSet\Services\EventLog\Application\amagent_uninstall")
if ($null -ne $rootKey)
{
$rootKey | Remove-Item -Recurse -Force
}
if ($null -ne $hklmKey)
{
$hklmKey | Remove-Item -Recurse -Force
}
foreach ($key in $otherKeys)
{
if (Test-Path $key)
{
$key | Remove-Item -Recurse -Force
}
}
#endregion
}
CleanUp-AxAgent
Comments
0 comments
Article is closed for comments.