Skip to content

KillProcessByName calls in uninstallHuntress can never match — process names are passed with .exe (lines 670-672) #157

Open

Description

@dbachen-dt

Line numbers refer to Datto-RMM/scripts/InstallHuntress.dattormm.comstore.ps1 at main (1089 lines).

uninstallHuntress calls the force-kill helper with file names including the extension (lines 669-672):

# Force kill the executables so they're not hangin around
KillProcessByName "HuntressAgent.exe"
KillProcessByName "HuntressUpdater.exe"
KillProcessByName "HuntressRio.exe"

KillProcessByName matches on the ProcessName property:

$processes = Get-Process | Where-Object { $_.ProcessName -eq $ProcessName }
$processCount = $processes | Measure-Object | Select-Object -ExpandProperty Count

if ($processCount -eq 0) {
    LogMessage "No processes with the name '$ProcessName' are currently running."
}

Get-Process returns ProcessName without the file extension — HuntressAgent, not HuntressAgent.exe. The equality test therefore never matches, $processCount is always 0, and all three calls take the zero-count branch. The log will always read No processes with the name 'HuntressAgent.exe' are currently running. regardless of whether the process is actually running.

Impact: the stated intent at line 669 is to force kill the executables so they aren't hanging around during uninstall. That never happens. Running agent processes hold open handles on files in the install directory, which makes the later cleanup step more likely to partially fail:

if (Test-Path $agentPath) {
    Remove-Item -LiteralPath $agentPath -Force -Recurse -ErrorAction SilentlyContinue
    LogMessage "Manual cleanup of Huntress folder: success"
}

Note that -ErrorAction SilentlyContinue means a partial removal still logs success. The residual directory left behind by a partially failed cleanup is the condition that triggers the folder-only install detection early-exit reported separately.

Fix options:

  • Pass base names: KillProcessByName "HuntressAgent" etc.
  • Or strip the extension inside the function: $ProcessName = [System.IO.Path]::GetFileNameWithoutExtension($ProcessName).
  • Or broaden the match to tolerate both forms, e.g. Where-Object { $_.ProcessName -eq $ProcessName -or $_.Path -like "*\$ProcessName" }.

Also worth verifying the cleanup result rather than logging success unconditionally — re-test the path after Remove-Item and log accordingly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions