{"id":67863,"date":"2006-02-28T13:24:00","date_gmt":"2006-02-28T13:24:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/02\/28\/how-can-i-re-launch-internet-explorer-if-no-other-instances-are-running\/"},"modified":"2006-02-28T13:24:00","modified_gmt":"2006-02-28T13:24:00","slug":"how-can-i-re-launch-internet-explorer-if-no-other-instances-are-running","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-re-launch-internet-explorer-if-no-other-instances-are-running\/","title":{"rendered":"How Can I Re-Launch Internet Explorer if No Other Instances are Running?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I re-launch Internet Explorer if no other instances are running?<BR><BR>&#8212; MT<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, MT. Thanks for the question. You know, nowadays everyone picks on poor little Internet Explorer (even though the vast majority of Windows users still use Internet Explorer). But now we have a question from someone who wants to make sure that Internet Explorer is always up and running. See, Internet Explorer: someone still loves you!<\/P>\n<P>As happy as we might have been for Internet Explorer, though, we have to admit that this question put us in a bit of a quandary. After all, there are several different ways to handle this problem, depending on whether you need Internet Explorer to re-start instantly or whether it\u2019s OK to wait awhile. After pondering the matter for awhile we decided to do what we always do: go with the simplest solution, one that (in this example) checks every 60 seconds to see if any instances of Internet Explorer are running. If there are, then the script simply goes back to sleep and waits another 60 seconds before checking again. If there <I>aren\u2019t<\/I> any instances of Internet Explorer running the script launches a new copy of Internet Explorer, then takes a quick nap and waits another 60 seconds before checking again.<\/P>\n<P>And, yes, that\u2019s somewhat similar to what a Scripting Guys day is like. Um, except for the part about waking up every 60 <I>seconds<\/I> in order to do something, if you know what we mean.<\/P>\n<P>Here\u2019s the script we came up with:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)\nSet objShell = CreateObject(&#8220;Wscript.Shell&#8221;)<\/p>\n<p>Do While True\n    Set colProcesses = objWMIService.ExecQuery _\n        (&#8220;Select * from Win32_Process Where Name = &#8216;iexplore.exe'&#8221;)\n    If colProcesses.Count = 0 Then\n        objShell.Run &#8220;iexplore.exe&#8221;\n    End If\n    Wscript.Sleep 60000\nLoop\n<\/PRE>\n<P>That\u2019s right: this is, at heart, just a run-of-the-mill WMI script. Because of that, it starts off by connecting to the WMI service on the local computer. But there is one key difference between this script and other WMI scripts. Usually at this point we say, \u201cBut you can also run this script against a remote computer.\u201d Unfortunately, that\u2019s not the case here. Technically you <I>could<\/I> run the script against a remote computer, but &#8211; at least on Windows XP and Windows Server 2003 &#8211; any instance of Internet Explorer you started up would run in an invisible window; you wouldn\u2019t be able to see it on the screen. That\u2019s a security feature built into the operating system: processes started remotely always run in a hidden window. Which, in turn, means that this script must be run on the local computer.<\/P>\n<TABLE id=\"EJD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Is there a workaround to this problem? As a matter of fact, there is, although it requires you to start the process locally rather than remotely. For an example of how you might do that, see this <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/sept05\/hey0906.mspx\"><B>Hey, Scripting Guy!column<\/B><\/A>.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After connecting to the WMI service we then create an instance of the <B>Wscript.Shell<\/B> object, which we\u2019ll use to spawn any new instances of Internet Explorer. (And, yes, we could have used WMI for this, but most people find it easier to run programs using Wscript.Shell rather than WMI.) We then set up a Do loop that runs for as long as True is equal to True. (Which, barring any new developments in philosophy, means the script will run forever. To stop the script you\u2019ll need to terminate the script process. If you\u2019re running in a command window under CScript that\u2019s as easy as pressing <B>Ctrl+C<\/B> or closing the command window.)<\/P>\n<P>So what do we do inside the loop? Well, to begin with, we use this code to retrieve a collection of all the processes named <B>iexplore.exe<\/B> that are currently running on the computer:<\/P><PRE class=\"codeSample\">Set colProcesses = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Process Where Name = &#8216;iexplore.exe'&#8221;)\n<\/PRE>\n<P>At the risk of spoiling the suspense, that\u2019s going to coincide with a collection of all the instances of Internet Explorer currently running on the computer. We then check to see if the value of the <B>Count<\/B> property (which tells us how many items are in the collection) is equal to 0:<\/P><PRE class=\"codeSample\">If colProcesses.Count = 0 Then\n<\/PRE>\n<P>If Count is equal to 0 that means there aren\u2019t any instances of Internet Explorer running on the machine. Therefore, we use the Shell object and the <B>Run<\/B> method to start up a brand-new instance:<\/P><PRE class=\"codeSample\">objShell.Run &#8220;iexplore.exe&#8221;\n<\/PRE>\n<P>And that\u2019s it. We then use the <B>Sleep<\/B> method to pause the script for 60 seconds (60,000 milliseconds). When 60 seconds are up, the script will wake up, loop around, and repeat the process, ad infinitum. If 60 seconds isn\u2019t the desired interval you can simply adjust the value. For example, this line of code runs the check every 30 seconds (30,000 milliseconds):<\/P><PRE class=\"codeSample\">Wscript.Sleep 30000\n<\/PRE>\n<P>And this one runs the check every 10 minutes (60,000 milliseconds per minute times 10 minutes):<\/P><PRE class=\"codeSample\">Wscript.Sleep 600000\n<\/PRE>\n<P>Admittedly, that only checks every 10 minutes to see if <I>Internet Explorer<\/I> is doing something. With the Scripting Guys, there\u2019s no point in checking every 10 minutes to see if <I>they\u2019re<\/I> doing anything: after all, you already know the answer to that, script or no script.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I re-launch Internet Explorer if no other instances are running?&#8212; MT Hey, MT. Thanks for the question. You know, nowadays everyone picks on poor little Internet Explorer (even though the vast majority of Windows users still use Internet Explorer). But now we have a question from someone who wants to [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[17,31,87,3,167,5],"class_list":["post-67863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-internet-explorer","tag-operating-system","tag-processes","tag-scripting-guy","tag-using-the-internet","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I re-launch Internet Explorer if no other instances are running?&#8212; MT Hey, MT. Thanks for the question. You know, nowadays everyone picks on poor little Internet Explorer (even though the vast majority of Windows users still use Internet Explorer). But now we have a question from someone who wants to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67863\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}