Skip to main content
Question

Kill All Processes - Run from automox


Forum|alt.badge.img

Hello Team-

We want to close all running processes without user intervention. I have tested this script locally and have no issues however, I am unable to get it to process through automox. Any ideas?

 

# Get the current PowerShell process
$currentProcess = Get-Process -Id $PID

# Processes to exclude from closure
$excludeProcesses = @("amagent", "powershell")

# Get a list of all running processes except the current PowerShell process and the excluded processes
$runningProcesses = Get-Process | Where-Object { $_.MainWindowTitle -ne "" -and $_.Id -ne $currentProcess.Id -and $_.ProcessName -notin $excludeProcesses }

# Iterate through the list of processes and close them
foreach ($process in $runningProcesses) {
    Write-Host "Closing $($process.ProcessName)..."
    $process.CloseMainWindow()
    
    # Wait for a few seconds to allow the application to close gracefully
    Start-Sleep -Seconds 5
    
    # If the application is still running, terminate it forcefully
    if (!$process.HasExited) {
        Write-Host "Forcefully terminating $($process.ProcessName)..."
        $process | Stop-Process -Force
    }
}

Write-Host "All running applications, except PowerShell, amagent have been closed."
 

AnthonyM-Automox

Good morning @ajamaya !

 

What problem are you running into testing through Automox? I don’t see a problem with the code myself but I could see a few spots where the action might not be exactly what you actually want to happen.

 

Look forward to your reply!

 

Anthony M.

 


Forum|alt.badge.img
  • Novice
  • January 25, 2024

@AnthonyM-Automox I attempt to run it out of automox but it never kills any of the applications. I am not sure if I need to exclude something out of it or how does automox process it. 


AnthonyM-Automox
ajamaya wrote:

@AnthonyM-Automox I attempt to run it out of automox but it never kills any of the applications. I am not sure if I need to exclude something out of it or how does automox process it. 

That is perplexing as I’m testing on my end and I don’t see any issues.

 

I do know CloseMainWindow() can fail in cases where the application can minimize to the system tray; but otherwise this is working as expected on my end.

 

What applications are you seeing fail to close, specifically?

 


Forum|alt.badge.img
  • Novice
  • January 25, 2024

None of the applications. Chrome, notepad++, Office 365 apps, etc. How are you running it out of automox?


Forum|alt.badge.img
  • Novice
  • January 26, 2024

I think this may be an issue with powershell. I have another msiexec command that runs locally but not within automox as well. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings