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.
Batch script
1 |
taskkill /F /IM <Image name of the app to be closed> /T |
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:
1 |
taskkill /F /PID <PID of the app to be closed> /T |
/PID
– Specifies the process-ID or the Process Identification Number of the process.
If you wish to see all the running processes on the endpoint device which you could terminate, the following script can be used:
1 |
tasklist |
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
1 |
stop-process –name <Name of the app to be closed> -force |
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:
1 |
stop-process –id <PID of the app to be closed> -force |
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.
1 |
tasklist |
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