Category filter

Script to force close apps on Windows

Devices sometimes encounter instances that compel the user to close currently running apps. This could be because you are using an outdated version of the app, running too many apps at once, are low on space, or your app has stopped running altogether. In such situations, admins can remotely run scripts on Windows devices to terminate the app without interaction with the system GUI using Execute Custom Script action.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

Batch script

The taskkill command terminates all instances of a process or application running on your system by using the following parameters:

/F – To forcefully close the process/app.

/IM – Specifies the image name of the process/app you want to terminate. The image name of the app is case sensitive.

/T – To terminate the PID along with any child processes associated with it.

The script additionally returns a message indicating the PID (Process Identification number) of the process that has been terminated.

E.g., To close the Notepad app currently running on your system,

taskkill /F /IM Notepad.exe /T

In case you want to suppress the errors and messages returned by closing the app, you can add the nul parameter to the script:

taskkill /F /IM Notepad.exe /T > nul

App can also be closed using its PID:

/PID – Specifies the process-ID or the Process Identification Number of the process.

Note:

Some applications run multiple processes simultaneously. Hence, the PIDs for all corresponding processes and subprocesses of that specific application should all be specified to close the application.

If you wish to see all the running processes on the endpoint device which you could terminate, the following script can be used:

The command returns the list of running processes with details regarding Image Name, PID, Session Name and Memory Usage.

If you want to close multiple applications at once, use the same taskkill command by specifying the image names of the applications separately as shown below:

taskkill /F /IM msedge.exe /IM chrome.exe /T

PowerShell script

The PowerShell script uses the stop-process command to terminate all the instances of the process/app specified.

–name is used to specify the name of the app/process to be closed and parameter –force is used to forcefully terminate the process/app. The name of the app is not case sensitive.

E.g., To close the Notepad app,

stop-process –name notepad -force

You could also close the app using the PID of the process:

Similar to the case of the batch script, if you want to list all the processes currently running in the endpoint device, you could use the tasklist command.

The details that are part of the list, like PID and image name, can later be used for terminating one of the running processes.

If you wish to close multiple applications at once, use the same stop-process command by specifying the names of the applications to be closed separated by a comma as shown below:

stop-process -name notepad, msedge, chrome -force

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository