Worklet: Prompt User to Close Application to Apply Updates

When an applications must be closed in order to update (e.g. Zoom, Notepad++, SnagIT) the Automox agent will not update the application if it is open, nor will it auto-close the application. This is intentional to prevent you from randomly losing unsaved work or dropping from a Zoom call.

This worklet can be used in conjunction with a patch policy by configuring its schedule to run 5 minutes before the application-specific patch policy is set to run. This increases the likelihood that applications that cannot be running during an update are indeed closed.

Evaluation:

#Force the worklet to run remediation code
exit 1

Remediation:
#This worklet takes the specified process and checks if it is running. If it isn’t, exit quietly. If it is, prompt the user to close the application so that updates can be applied.

#Set the name of the application you want to affect
$process = "notepad"

#Check if $process is running. If it's running, ask the user to close it, if it isn't running then exit quietly.
$process_running = Get-Process $process -ErrorAction SilentlyContinue

if ( !$process_running ) {
	#If the process is not running then there's nothing to do. Exit quietly.
	 Write-Host "$process was not running: nothing to close." }
else {
#Play a sound with the pop-up message
[system.media.systemsounds]::Hand.play()

#Trigger the pop-up message with a Ok/Cancel option
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$UserResponse = [System.Windows.Forms.MessageBox]::Show("$process must be updated on your system. 

Please save your work and click OK to close the application." , "Status" , 1)

#If user clicked OK, try to close the app gracefully
    if ( $UserResponse -eq "OK" ) {
	    Write-Host "Closing $process application."
	    $process_running.CloseMainWindow()
	    
        ##Optional: Uncomment the stanza below to force kill the process after X seconds if graceful exit failed
	    #Sleep 60
	    #if ( !$process_running.HasExited ) {
	    #	$process_running | Stop-Process -Force }
    	} 
    else 
    #If user clicked Cancel, exit and do nothing
    { 
    Write-Host "$process update not applied: user chose to keep the app open." 
	Exit
    }
}
3 Likes

Hi @Stambo,

First, thanks for your worklet. It definitely will help us updating some application. I just need to figure out how the pop-up window will work. I run the worklet to a device but pop-window notification is not showing up. Activity report showing it run the script successfully. Any insight what might went wrong?

Thanks!
Ulyssis

Hi Ulyssis,

Which app are you trying to trigger the notification for?

Hi @Jeff S via Automox Community,

Thanks for your reply.

Slack

Zoom

Notepad++

I will also include Chrome and different browser.

Echoing what @uapilado is saying, would be cool to alter this script to include all of the “unclosable” apps that automox offers to patch instead of pick/choosing

We’re working on a generic version where you can fill in whatever process you want to kill and Automox will take it out back behind the woodshed and…well you know.

Is there anyway to get a version that can be called as part of normal operations, rather than to specifically call this worklet?

For example, where we specify the reboot notification, can we have this ‘close the app for patching’ notification as an option?

This would significantly speed up patching, rather than relying on an endpoint not having the application closed.

3 Likes