{"id":66813,"date":"2006-07-27T18:16:00","date_gmt":"2006-07-27T18:16:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/07\/27\/how-can-i-display-a-message-box-that-has-no-buttons-and-that-disappears-after-a-specified-period-of-time\/"},"modified":"2006-07-27T18:16:00","modified_gmt":"2006-07-27T18:16:00","slug":"how-can-i-display-a-message-box-that-has-no-buttons-and-that-disappears-after-a-specified-period-of-time","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-display-a-message-box-that-has-no-buttons-and-that-disappears-after-a-specified-period-of-time\/","title":{"rendered":"How Can I Display a Message Box That Has No Buttons, and That Disappears After a Specified Period of Time?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I would like to display a message box for a set amount of time and then have it disappear. However, I\u2019d prefer that this message box not have a close button, or have anything else that would allow the user to close the message, minimize the message, etc. How can I do that?<BR><BR>&#8212; D<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, D. You know, this question takes us back to the beginning days of <I>Hey, Scripting Guy!<\/I> Back when we first started, it seemed like each and every column would go like this:<\/P>\n<TABLE class=\"dataTable\" id=\"E6C\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P>Hey, Scripting Guy! How can I do <I>x<\/I> in a script? <\/P>\n<P>&#8212; SP<\/P>\n<P>Hey, SP. You can\u2019t.<\/P>\n<P>But, wait, don\u2019t go yet: we have a workaround for you. All you have to do is \u2026.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>The first time we told people they couldn\u2019t do something and then immediately turned around and told them how to do it, well, that was pretty cute; by the 138<SUP>th<\/SUP> time, hwoever, it wasn\u2019t quite so cute anymore. Because of that we swore on Peter\u2019s grave that we would never use such a corny opener ever again. <\/P>\n<P>Which didn\u2019t make Peter all that happy, considering the fact that he\u2019s still very much alive. In our defense, though, with Peter it\u2019s sometimes hard to tell.<\/P>\n<P>So instead of saying that you can\u2019t display a message box that doesn\u2019t have a button on it (and then \u2013 after dashing your hopes \u2013 telling you that we have a workaround anyway) we\u2019ll just talk about something else. You know\u2026 we\u2019ll talk about \u2026 stuff. Right. Oh: baseball. What\u2019s up with that? And, that one thing, the one that was in the newspaper? That was really something, wasn\u2019t \u2026.<\/P>\n<P>Oh, what the heck: the truth is, D, you can\u2019t display a message box (for any amount of time) that doesn\u2019t include a button of some kind. But, wait, don\u2019t go yet: we have a workaround for you.<\/P>\n<TABLE class=\"dataTable\" id=\"EWD\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Sorry. But that just had to be said.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>So what <I>kind<\/I> of workaround do we have? This kind:<\/P><PRE class=\"codeSample\">&lt;html&gt;\n    &lt;HTA:APPLICATION \n        Caption=&#8221;no&#8221;\n    &gt;<\/p>\n<p>    &lt;script language = &#8220;VBScript&#8221;&gt;\n        Sub Window_OnLoad\n            idTimer = window.setTimeout(&#8220;PausedSection&#8221;, 5000, &#8220;VBScript&#8221;)\n        End Sub<\/p>\n<p>        Sub PausedSection\n            window.close\n        End Sub\n    &lt;\/script&gt;<\/p>\n<p>    &lt;body&gt;\n        &lt;p&gt;Your message goes here&lt;\/p&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;\n<\/PRE>\n<P>What we\u2019ve got here is a simple little HTA (HTML Application). An HTA is similar to an HTML file; the big difference is that HTAs use the file extension .HTA and are designed to run locally instead of over the Internet. In addition, you can create an HTA that does not include a close button (or even a title bar), and you can display any message you choose to display. Technically it\u2019s not a message box, but we\u2019re assuming that doesn\u2019t matter: you just want something to display on screen for a set amount of time and then disappear. On top of that, you don\u2019t want to give the user an obvious way to dismiss that message before the time expires. The little HTA we\u2019re about to show you meets all those criteria.<\/P>\n<TABLE class=\"dataTable\" id=\"EIE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Where can you learn more about HTAs? <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/htas.mspx\"><B>Funny you should ask<\/B><\/A> \u2026.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>So how do we get this all to work? Well, to begin with, copy the preceding code, paste it into Notepad or some other script editor, and then save the file with a .HTA file extension. First things first.<\/P>\n<P>Now let\u2019s talk about the file you just created. The HTA itself is divided into three sections: basic properties for the HTA, the message displayed in the body of the HTA, and the code that causes the HTA to dismiss itself after a set amount of time (in this example, after 5 seconds). Let\u2019s start off by looking at the section where we configure the HTA properties:<\/P><PRE class=\"codeSample\">&lt;HTA:APPLICATION \n    Caption=&#8221;no&#8221;\n&gt;\n<\/PRE>\n<P>As you can see, we set only one property here: we set the <B>Caption<\/B> property to No. What that does is remove the title bar, the close button, the minimize and maximize buttons, and just about everything else from the HTA window, leaving you with something that looks like this:<\/P><IMG height=\"250\" alt=\"Spacer\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/nobutton1.jpg\" width=\"400\" border=\"0\"> \n<P><BR>Nice, huh? (You\u2019re right, it <I>does<\/I> look a lot like the list of Scripting Guy achievements over the past year or so, doesn\u2019t it?)<\/P>\n<P>If that\u2019s a bit <I>too<\/I> severe for you, then use this code and set the <B>SysMenu<\/B> property to No:<\/P><PRE class=\"codeSample\">&lt;HTA:APPLICATION \n    SysMenu=&#8221;no&#8221;\n&gt;\n<\/PRE>\n<P>When you do that you\u2019ll still have the title bar, but no close, minimize, or maximize buttons, so there\u2019s still no obvious way to close the HTA. (To dismiss it you\u2019d need to terminate the Mshta.exe process.)<\/P><IMG height=\"250\" alt=\"Spacer\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/nobutton2.jpg\" width=\"400\" border=\"0\"> \n<P><BR>If you go this route you might also want to use the &lt;TITLE&gt; tag to give the page a title:<\/P><PRE class=\"codeSample\">&lt;head&gt;\n    &lt;title&gt;Test&lt;\/title&gt;\n&lt;\/head&gt;\n<\/PRE>\n<P>Just insert that right under the &lt;HTML&gt; tag. That way you\u2019ll have a custom caption (in this case, <I>Test<\/I>) that appears in the title bar. If you don\u2019t specifically assign a title then the file path will appear in the title bar.<\/P>\n<P>If you thought it was easy to configure the HTA properties, well, have we got news for you: it\u2019s even easier to specify a message for your HTA:<\/P><PRE class=\"codeSample\">&lt;body&gt;\n    &lt;p&gt;Your message goes here&lt;\/p&gt;\n&lt;\/body&gt;\n<\/PRE>\n<P>Just type your message in the space labeled <B>Your message goes here<\/B>, and you\u2019re on your way. And because this <I>is<\/I> HTML you can change fonts and font sizes, add graphics, and do anything else that can be done in HTML. But we\u2019ll leave that up to you. (Hey, it wouldn\u2019t be any fun for you if we did <I>everything<\/I>, now would it?)<\/P>\n<P>That brings us to the &lt;SCRIPT&gt; section, which is where we control the amount of time that the HTA appears onscreen. To do that, we use these two subroutines:<\/P><PRE class=\"codeSample\">Sub Window_OnLoad\n    idTimer = window.setTimeout(&#8220;PausedSection&#8221;, 5000, &#8220;VBScript&#8221;)\nEnd Sub<\/p>\n<p>Sub PausedSection\n    window.close\nEnd Sub\n<\/PRE>\n<P>You\u2019re right: there isn\u2019t much happening here, is there? To begin with, we have a subroutine named <B>Window_OnLoad<\/B>; as you probably know, the Window_OnLoad subroutine is designed to automatically run any time an HTA is loaded or refreshed. As you can see, we don\u2019t do much inside this subroutine; in fact, all that we <I>do<\/I> do is create a timer named idTimer. That timer is designed to wait a specified number of seconds and then call a second subroutine (PausedSection). What will this second subroutine do? You\u2019ll find out in just a second.<\/P>\n<P>Here\u2019s what the code looks like:<\/P><PRE class=\"codeSample\">idTimer = window.setTimeout(&#8220;PausedSection&#8221;, 5000, &#8220;VBScript&#8221;)\n<\/PRE>\n<P>As it turns out, to create a timer all we have to do is call the <B>setTimeout <\/B>method, passing three parameters:<\/P>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>PausedSection<\/B>, the subroutine we want to call after the five-second pause.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>5000<\/B>, the number of milliseconds to pause. As you probably figured out, 1,000 milliseconds is equal to one second. Want to display the message for 20 seconds? No problem; just change this parameter to 20000.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>VBScript<\/B>, the script language we\u2019re using.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>In other words, each time we load the HTA the Window_OnLoad subroutine sets a timer. That timer will click off 5,000 milliseconds and then run a subroutine name PausedSection. In turn, that subroutine does one thing and one thing only; it closes the HTA:<\/P><PRE class=\"codeSample\">Sub PausedSection\n    window.close\nEnd Sub\n<\/PRE>\n<P>The net result? An \u201cunclosable\u201d HTA will pop up on screen, display your message, and then automatically disappear after 5 seconds. Which sounds like exactly the sort of behavior you were hoping to get.<\/P>\n<TABLE class=\"dataTable\" id=\"ERH\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Good point: by default the HTA window <I>is<\/I> a little big, and isn\u2019t centered on the screen, either. Fortunately, we have a column <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/sept05\/hey0919.mspx\"><B>here<\/B><\/A> and another column <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct05\/hey1010.mspx\"><B>here<\/B><\/A> that can help you resolve those issues.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After you\u2019ve created the .HTA file all you have to do within your script (that is, within the .vbs file) is include code that will call and display this HTA. Something along these lines ought to do the trick: <\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nobjShell.Run &#8220;no_button.hta&#8221;\n<\/PRE>\n<P>We hope that helps, D. Granted, it\u2019s not <I>exactly<\/I> what you asked for; for one thing, it\u2019s not a message box. But seeing as how you <I>can\u2019t<\/I> display a message box that doesn\u2019t have any buttons, well, this seems like the next best thing.<\/P>\n<P>And, yes, some people <I>would<\/I> call this a workaround. But the Scripting Guys would never do that. <\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/jul06\/hey0727.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/jul06\/hey0727.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I would like to display a message box for a set amount of time and then have it disappear. However, I\u2019d prefer that this message box not have a close button, or have anything else that would allow the user to close the message, minimize the message, etc. How can I do [&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":[3,4,5,30],"class_list":["post-66813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I would like to display a message box for a set amount of time and then have it disappear. However, I\u2019d prefer that this message box not have a close button, or have anything else that would allow the user to close the message, minimize the message, etc. How can I do [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66813","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=66813"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66813\/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=66813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}