{"id":558,"date":"2012-01-20T01:52:46","date_gmt":"2012-01-19T20:22:46","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=558"},"modified":"2012-01-20T01:56:56","modified_gmt":"2012-01-19T20:26:56","slug":"3-different-ways-to-close-an-application-through-task-manager-using-qtp","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/","title":{"rendered":"3 different ways to close an application through Task Manager using QTP"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Verdana;\">\n<p>In this article, we&#8217;ll see how to use QTP to close an application through Windows Task Manager. We all know that Windows Task Manager is an application available in Windows Operating Systems which provides detailed information about all the processes\/tasks currently running in your system. To manually close any process\/task from the task manager, <!--more-->all you have to do is select the task\/process in the task manager and use the End Task\/End Process button to close the task. Lets see how the same can be achieved using QTP.<\/p>\n<p>QTP provides 3 built-in methods using which you can close a process from Task Manager. All these 3 methods are part of <strong>SystemUtil<\/strong> object. These 3 methods use the Process ID, Process Name &amp; Application Window Title to access and then close the process in Task Manager. <em>QTP initially tries to close the process by sending WM_CLOSE message to the process window. If the process is still open after 5 seconds, QTP then terminates the process.<\/em><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"196\"><strong>Method Name<\/strong><\/td>\n<td valign=\"top\" width=\"369\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"196\">CloseProcessByName<\/td>\n<td valign=\"top\" width=\"369\">Closes a process based on its name.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"196\">CloseProcessById<\/td>\n<td valign=\"top\" width=\"369\">Closes a process according to its Process ID (PID)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"196\">CloseProcessByWndTitle<\/td>\n<td valign=\"top\" width=\"369\">Closes a task based on the title of the window<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Task Manager Process\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png\" alt=\"Task Manager Process\" width=\"421\" height=\"520\" \/><\/p>\n<p><span><br \/>\n<\/span><br \/>\nLets see some examples on how to use these SystemUtil methods.<br \/>\n<em> <\/em><br \/>\n<strong>1. CloseProcessByName &#8211; <\/strong>This method closes the process based on its image name in the task manager. It returns a long value which represents the number of instances of the application that are closed using this method.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Open 3 notepad instances\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\n\r\n'Close the notepads using the image name\r\niReturn = SystemUtil.CloseProcessByName(&quot;notepad.exe&quot;)\r\nmsgbox iReturn 'Returns 3 as total 3 notepads are closed\r\n<\/pre>\n<p><em> <\/em><br \/>\n<strong>2. CloseProcessById &#8211; <\/strong>This method closes a process based on its Process ID and returns a) True if the process was closed successfully b) False if the process was not closed.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim pID_Notepad, pID_Excel\r\n\r\n'Open notepad and excel applications\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;excel.exe&quot;\r\n\r\n'Find Process IDs of both the applications\r\npID_Notepad = Window(&quot;regexpwndtitle:=Notepad&quot;).GetROProperty(&quot;process id&quot;)\r\npID_Excel = Window(&quot;regexpwndtitle:=XLMAIN&quot;).GetROProperty(&quot;process id&quot;)\r\n\r\n'Close both the applications\r\niReturn_N = SystemUtil.CloseProcessById(pID_Notepad)\r\niReturn_E = SystemUtil.CloseProcessById(pID_Excel)\r\n\r\nmsgbox iReturn_N 'Returns True\r\nmsgbox iReturn_E 'Returns True\r\n<\/pre>\n<p><em> <\/em><br \/>\n<strong>3. CloseProcessByWndTitle &#8211; <\/strong>This method closes a process based on its window title and returns a long value that represents the number of instances of the applications that are closed.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Open notepad and excel applications\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;excel.exe&quot;\r\n\r\n'Close all the tasks where the window title exactly matches &quot;Untitled - Notepad&quot;\r\nSystemUtil.CloseProcessByWndTitle &quot;Untitled - Notepad&quot;, False\r\n'Close all the tasks where the window title contains the string &quot;Excel&quot;\r\nSystemUtil.CloseProcessByWndTitle &quot;Excel&quot;, True\r\n<\/pre>\n<p><span><br \/>\n<\/span><br \/>\n<em>Other than these 3 methods, SystemUtil object provides 2 more in-built methods that can be used to close an application. These methods are &#8211; <\/em><br \/>\n<em> <\/em><br \/>\n<strong>a. CloseDescendentProcesses &#8211; <\/strong>This method closes all the processes that are opened by QTP. It returns a long value which indicates the number of instances of the application that are closed using this method.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Open notepad and excel applications using QTP\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;excel.exe&quot;\r\n\r\n'Close all the processes opened using QTP\r\niReturn = SystemUtil.CloseDescendentProcesses\r\nmsgbox iReturn\r\n<\/pre>\n<p><em> <\/em><br \/>\n<strong>b. CloseProcessByHwnd &#8211; <\/strong>This method closes a process based on its window handle (The window handle can be found out using &#8216;hwnd&#8217; property). This method returns a) True &#8211; if the process is closed successfully, and b) False if the process is not closed.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim hwnd_Notepad, hwnd_Excel\r\n\r\n'Open notepad and excel applications\r\nSystemUtil.Run &quot;notepad.exe&quot;\r\nSystemUtil.Run &quot;excel.exe&quot;\r\n\r\n'Find Handles of both the application windows\r\nhwnd_Notepad = Window(&quot;regexpwndtitle:=Notepad&quot;).GetROProperty(&quot;hwnd&quot;)\r\nhwnd_Excel = Window(&quot;regexpwndtitle:=XLMAIN&quot;).GetROProperty(&quot;hwnd&quot;)\r\n\r\n'Close both the applications\r\niReturn_N = SystemUtil.CloseProcessByHwnd(hwnd_Notepad)\r\niReturn_E = SystemUtil.CloseProcessByHwnd(hwnd_Excel)\r\n\r\nmsgbox iReturn_N 'Returns True\r\nmsgbox iReturn_E 'Returns True\r\n<\/pre>\n<p><em>This was all about the SystemUtil built-in methods that can be used to close an application process. Did you like this article? Do let us know using the comments section. Happy reading&#8230;<\/em><br \/>\n<span><br \/>\n<\/span><\/p>\n<\/div>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you enjoyed this article, you can join our blog to get new posts delivered directly in your inbox.<\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p><span><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;ll see how to use QTP to close an application through Windows Task Manager. We all know that Windows Task Manager is an application available in Windows Operating Systems which provides detailed information about all the processes\/tasks currently running in your system. To manually close any process\/task from the task manager,<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[59,60,57,56,58,55],"class_list":["post-558","post","type-post","status-publish","format-standard","hentry","category-qtp-concepts","tag-closedescendentprocesses","tag-closeprocessbyhwnd","tag-closeprocessbyid","tag-closeprocessbyname","tag-closeprocessbywndtitle","tag-task-manager"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>3 different ways to close an application through Task Manager using QTP - XX<\/title>\n<meta name=\"description\" content=\"This article describes how to close an application from Task Manager using SystemUtil&#039;s built-in methods such as CloseProcessByName, CloseProcessById, CloseProcessByWndTitle\" \/>\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.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/\",\"name\":\"3 different ways to close an application through Task Manager using QTP - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png\",\"datePublished\":\"2012-01-19T20:22:46+00:00\",\"dateModified\":\"2012-01-19T20:26:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"description\":\"This article describes how to close an application from Task Manager using SystemUtil's built-in methods such as CloseProcessByName, CloseProcessById, CloseProcessByWndTitle\",\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"3 different ways to close an application through Task Manager using QTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"3 different ways to close an application through Task Manager using QTP - XX","description":"This article describes how to close an application from Task Manager using SystemUtil's built-in methods such as CloseProcessByName, CloseProcessById, CloseProcessByWndTitle","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.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/","name":"3 different ways to close an application through Task Manager using QTP - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png","datePublished":"2012-01-19T20:22:46+00:00","dateModified":"2012-01-19T20:26:56+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"description":"This article describes how to close an application from Task Manager using SystemUtil's built-in methods such as CloseProcessByName, CloseProcessById, CloseProcessByWndTitle","breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/task-manager-process.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/3-different-ways-to-close-an-application-through-task-manager-using-qtp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"3 different ways to close an application through Task Manager using QTP"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=558"}],"version-history":[{"count":14,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/558\/revisions"}],"predecessor-version":[{"id":1024,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/558\/revisions\/1024"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}