If you’re unable to uninstall the Windows Automox Agent due to file corruption, a missing amagent.exe file, or the need to clean up previous installations, this issue can be resolved using a dedicated PowerShell script or through manual remediation steps.
Issue Overview
Common scenarios where this issue arises include:
- Corrupted installation files are preventing the standard uninstallation process.
- Missing or deleted amagent.exe.
- General cleanup of older Automox Agent installations.
Prerequisites
Before running the script, ensure the following:
- You have access to a Windows account with administrative privileges.
- PowerShell is installed and accessible on your device.
- You understand how to run PowerShell scripts with elevated permissions.
Steps to Resolve - Manual
Stopping the Automox Agent can be done in several ways. Stop all of the processes below, not just amagent, because any one of them still running holds the install folder open and causes the removal to fail:
- Choose "Stop" in the Windows Services screen.
- Use PowerShell to stop them, in this order:
Stop-Process -Name amagent-watchdog,amagent,amagent-ui,remotecontrold,wdk,otto,osqueryi,AgentNotifier -Force -ErrorAction SilentlyContinue
The watchdog is stopped first because it restarts the tray process every 30 seconds.
The Automox Agent application can be uninstalled in multiple ways:
- Using the Windows "Add or Remove Programs" UI.
- Delete the device from the Automox console: Taking Action on a Device
- Search the following registry paths for directories with the "Automox Agent" key and run the standard MSIEXEC uninstall commands:
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\UninstallHKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Steps to Resolve - Script
- Use the CleanUp-AxAgent script included in this article.
- Open PowerShell as an Administrator:
- Right-click the PowerShell application and select Run as Administrator.
- Run the script following the instructions provided in the file.
Important: This script must be executed with elevated permissions to ensure all files are removed successfully.
Verify the removal before reinstalling. If the script reports that it could not remove a file, the cleanup did not finish, and reinstalling on top of it will not resolve the original problem. Confirm the folder is gone by running Test-Path "C:\Program Files (x86)\Automox" and Test-Path "C:\Program Files\Automox". Both should return False. If either returns True, reboot the device, run the script again, and confirm before installing the agent.
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
Version 1.3
Released: 2026-09-15
Author: Automox Support
Changelog:
1.3 - Stop EVERY Automox image that runs from the install folder, not just
amagent / remotecontrold / amagent-watchdog. wdk.exe in particular is
written to the install folder and held open during a scan; when it
survived removal the device stayed pinned to an old WDK version and
every later scan failed, while this script still reported success.
Also: name the files that could not be deleted instead of continuing
silently, and clean both the 32-bit and 64-bit install paths.
1.2 - Also stop the Automox Agent Watchdog process (amagent-watchdog.exe) and
remove the 'watchdog' service. The watchdog was introduced in agent 2.3.34
and was not handled before, so it kept the install folder locked (causing
"Was not able to remove") and was left behind as an orphaned service.
.EXAMPLE
CleanUp-AxAgent
.LINK
http://www.automox.com
#>
#region uninstall
# Uninstall with MSI method if found present
# Define Values
# Both architectures' install folders. A device can carry leftovers in either,
# and cleaning only one of them leaves the other behind.
$installPaths = @("${env:ProgramFiles(x86)}\Automox", "${env:ProgramFiles}\Automox") | Select-Object -Unique
$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 "Proceeding with Automox cleanup steps"
}
#endregion
#region cleanup
# Every Automox image that can run out of the install folder. Any one of these
# still running holds a file open and turns the folder removal below into a
# silent no-op. Order matters: the watchdog respawns the tray every 30 seconds,
# so it has to go first.
$axProcessNames = @(
'amagent-watchdog',
'amagent',
'amagent-ui',
'remotecontrold',
'wdk',
'otto',
'osqueryi',
'AgentNotifier'
)
foreach ($procName in $axProcessNames)
{
$axProcess = Get-Process -Name $procName -ErrorAction SilentlyContinue
if ($null -ne $axProcess)
{
Try
{
Write-Output "Stopping $procName process"
Stop-Process -InputObject $axProcess -Force -ErrorAction Stop
}
Catch
{
Write-Error "Unable to stop $procName.`nFiles may be left behind in the Automox install folder";
}
}
}
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='amagent'"
if ($null -ne $svcExists)
{
Write-Output "Removing Automox agent service"
$svcExists | Remove-WmiObject
# Test for successful removal of Automox agent
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='amagent'"
if ($null -ne $svcExists)
{
Write-Output "Automox agent service was not able to be removed. Try rebooting and re-run script."
}
}
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='remotecontrold'"
if ($null -ne $svcExists)
{
Write-Output "Removing Automox remote control service"
$svcExists | Remove-WmiObject
# Test for successful removal of Automox remote control service
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='remotecontrold'"
if ($null -ne $svcExists)
{
Write-Output "Automox remote control service was not able to be removed. Try rebooting and re-run script."
}
}
# Remove the watchdog service. Guard on the binary path so we never remove a
# non-Automox service that happens to be named 'watchdog'.
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='watchdog'" | Where-Object { $_.PathName -match 'amagent-watchdog' }
if ($null -ne $svcExists)
{
Write-Output "Removing Automox Agent Watchdog service"
$svcExists | Remove-WmiObject
# Test for successful removal of the watchdog service
$svcExists = Get-WmiObject -Class Win32_Service -Filter "Name='watchdog'" | Where-Object { $_.PathName -match 'amagent-watchdog' }
if ($null -ne $svcExists)
{
Write-Output "Automox Agent Watchdog service was not able to be removed. Try rebooting and re-run script."
}
}
# 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
}
# Remove the install folder(s) and REPORT anything that survives. The previous
# version suppressed per-file errors, so a single locked file (commonly wdk.exe)
# left the device broken while this script still reported success.
foreach ($path in $installPaths)
{
if (-not (Test-Path $path)) { continue }
# Account for removal of exec#### folders that may give access to path denied errors
Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.PSIsContainer -eq $true -and (Get-ChildItem -Path $_.FullName -ErrorAction SilentlyContinue) -eq $null } |
Remove-Item -ErrorAction SilentlyContinue
# Remove Automox folder
$path | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
if (Test-Path $path)
{
$remaining = @(Get-ChildItem -Path $path -Recurse -Force -ErrorAction SilentlyContinue)
Write-Warning "Was not able to remove $path"
if ($remaining.Count -gt 0)
{
Write-Warning "The following could not be deleted, most likely because a process still has them open:"
foreach ($item in $remaining) { Write-Warning " $( $item.FullName )" }
}
Write-Warning "Reboot the device, run this script again, and confirm this message does not appear before reinstalling the agent."
}
else
{
Write-Output "Removed $path"
}
}
# 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