{"id":42749,"date":"2023-01-27T07:02:17","date_gmt":"2023-01-27T07:02:17","guid":{"rendered":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/?p=42749"},"modified":"2023-03-21T11:55:10","modified_gmt":"2023-03-21T11:55:10","slug":"script-to-force-close-apps-on-windows","status":"publish","type":"post","link":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/","title":{"rendered":"Script to force close apps on Windows"},"content":{"rendered":"<style>\n.crayon-line {\n    max-width: 20vw !important;\n}\ncode{\n    font-size: 100%;\n    display: inline-block;\n    line-height: 1.8;\n}\n.height-adj{\nline-height: 1.8 !important;\n}\n<\/style>\n<p>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  <a href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/executing-custom-scripts-for-windows\/\" rel=\"noopener\" target=\"_blank\"> Execute Custom Script<\/a> action.<\/p>\n    \t\t<div class=\"hts-messages hts-messages--danger  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Disclaimer:<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t <\/p>\n<p>The sample scripts provided below are adapted from third-party open-source sites.<\/p>\n<p>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<h2>Batch script<\/h2>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"Batch script to force close apps\"> \r\n\r\ntaskkill \/F \/IM <Image name of the app to be closed> \/T  \r\n\r\n<\/pre>\n<\/div>\n<p>The <code>taskkill<\/code> command terminates all instances of a process or application running on your system by using the following parameters: <\/p>\n<p><code>\/F<\/code> &#8211; To forcefully close the process\/app. <\/p>\n<p><code>\/IM<\/code> &#8211; Specifies the image name of the process\/app you want to terminate. The image name of the app is case sensitive. <\/p>\n<p><code>\/T<\/code> &#8211; To terminate the PID along with any child processes associated with it. <\/p>\n<p>The script additionally returns a message indicating the PID (Process Identification number) of the process that has been terminated. <\/p>\n<p>E.g., To close the Notepad app currently running on your system, <\/p>\n<p><code>taskkill \/F \/IM Notepad.exe \/T<\/code><\/p>\n<p>In case you want to suppress the errors and messages returned by closing the app, you can add the <code>nul<\/code> parameter to the script: <\/p>\n<p><code>taskkill \/F \/IM Notepad.exe \/T > nul<\/code><\/p>\n<p>App can also be closed using its PID: <\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"Batch script to force close app using PID\"> \r\n\r\ntaskkill \/F \/PID <PID of the app to be closed> \/T \r\n\r\n<\/pre>\n<\/div>\n<p><code>\/PID<\/code> &#8211; Specifies the process-ID or the Process Identification Number of the process. <\/p>\n    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Note:<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t <\/p>\n<p>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.<\/p>\n<p>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<p>If you wish to see all the running processes on the endpoint device which you could terminate, the following script can be used: <\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"Batch script to see all the running processes on the endpoint\"> \r\n\r\ntasklist \r\n\r\n<\/pre>\n<\/div>\n<p>The command returns the list of running processes with details regarding Image Name, PID, Session Name and Memory Usage. <\/p>\n<p>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: <\/p>\n<p><code>taskkill \/F \/IM msedge.exe \/IM chrome.exe \/T<\/code><\/p>\n<h2>PowerShell script<\/h2>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"PowerShell script to force close apps\"> \r\n\r\n\r\nstop-process \u2013name <Name of the app to be closed> -force \r\n\r\n<\/pre>\n<\/div>\n<p>The PowerShell script uses the <code>stop-process<\/code> command to terminate all the instances of the process\/app specified.<\/p>\n<p><code>\u2013name<\/code> is used to specify the name of the app\/process to be closed and parameter <code>\u2013force<\/code> is used to forcefully terminate the process\/app. The name of the app is not case sensitive. <\/p>\n<p>E.g., To close the Notepad app, <\/p>\n<p><code>stop-process \u2013name notepad -force<\/code> <\/p>\n<p>You could also close the app using the PID of the process: <\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"PowerShell script to force close apps on Windows using PID\"> \r\n\r\n\r\nstop-process \u2013id <PID of the app to be closed> -force \r\n\r\n<\/pre>\n<\/div>\n<p>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 <code>tasklist<\/code> command.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:17 line-height:32 top-set:false bottom-set:false toolbar:1 show-plain:3 lang:default decode:true inline-margin:\" title=\"PowerShell script to see all the running processes on the endpoint\"> \r\n\r\ntasklist \r\n\r\n<\/pre>\n<\/div>\n<p>The details that are part of the list, like PID and image name, can later be used for terminating one of the running processes.<\/p>\n<p>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: <\/p>\n<p><code>stop-process -name notepad, msedge, chrome -force<\/code> <\/p>\n    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Notes:<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t <\/p>\n<ul>\n<li> It is recommended to manually validate the script execution on a system before executing the action in bulk. <\/li>\n<li> Hexnode will not be responsible for any damage\/loss to the system on the behavior of the script. <\/li>\n<\/ul>\n<p>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":60,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[265,263],"tags":[320],"class_list":["post-42749","post","type-post","status-publish","format-standard","hentry","category-windows-sample-script-repository","category-sample-script-repository","tag-app-management"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Script to force close apps on Windows - Hexnode Help Center<\/title>\n<meta name=\"description\" content=\"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Script to force close apps on Windows - Hexnode Help Center\" \/>\n<meta property=\"og:description\" content=\"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/\" \/>\n<meta property=\"og:site_name\" content=\"Hexnode Help Center\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-27T07:02:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-21T11:55:10+00:00\" \/>\n<meta name=\"author\" content=\"Avaneeth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Avaneeth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/\",\"url\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/\",\"name\":\"Script to force close apps on Windows - Hexnode Help Center\",\"isPartOf\":{\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#website\"},\"datePublished\":\"2023-01-27T07:02:17+00:00\",\"dateModified\":\"2023-03-21T11:55:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/fabc99412f4e3088b46e3280685cf435\"},\"description\":\"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Script to force close apps on Windows\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#website\",\"url\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/\",\"name\":\"Hexnode Help Center\",\"description\":\"Mobile Device Management Help\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/fabc99412f4e3088b46e3280685cf435\",\"name\":\"Avaneeth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e25b5c17aa0ebab8dcac00c1c440d02b25f0d3607cb67d11e8d85b14243ffdb8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e25b5c17aa0ebab8dcac00c1c440d02b25f0d3607cb67d11e8d85b14243ffdb8?s=96&d=mm&r=g\",\"caption\":\"Avaneeth\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Script to force close apps on Windows - Hexnode Help Center","description":"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/","og_locale":"en_US","og_type":"article","og_title":"Script to force close apps on Windows - Hexnode Help Center","og_description":"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.","og_url":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/","og_site_name":"Hexnode Help Center","article_published_time":"2023-01-27T07:02:17+00:00","article_modified_time":"2023-03-21T11:55:10+00:00","author":"Avaneeth","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Avaneeth","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/","url":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/","name":"Script to force close apps on Windows - Hexnode Help Center","isPartOf":{"@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#website"},"datePublished":"2023-01-27T07:02:17+00:00","dateModified":"2023-03-21T11:55:10+00:00","author":{"@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/fabc99412f4e3088b46e3280685cf435"},"description":"Script to force close apps and processes on your Windows 10\/11 devices. You can remotely execute these scripts on Windows with Hexnode\u2019s Execute Custom Script action.","breadcrumb":{"@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/script-to-force-close-apps-on-windows\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/"},{"@type":"ListItem","position":2,"name":"Script to force close apps on Windows"}]},{"@type":"WebSite","@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#website","url":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/","name":"Hexnode Help Center","description":"Mobile Device Management Help","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/fabc99412f4e3088b46e3280685cf435","name":"Avaneeth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e25b5c17aa0ebab8dcac00c1c440d02b25f0d3607cb67d11e8d85b14243ffdb8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e25b5c17aa0ebab8dcac00c1c440d02b25f0d3607cb67d11e8d85b14243ffdb8?s=96&d=mm&r=g","caption":"Avaneeth"}}]}},"_links":{"self":[{"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/posts\/42749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/comments?post=42749"}],"version-history":[{"count":10,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/posts\/42749\/revisions"}],"predecessor-version":[{"id":43710,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/posts\/42749\/revisions\/43710"}],"wp:attachment":[{"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/media?parent=42749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/categories?post=42749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexnode.com\/mobile-device-management\/help\/wp-json\/wp\/v2\/tags?post=42749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}