{"id":71163,"date":"2004-10-22T11:08:00","date_gmt":"2004-10-22T11:08:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/10\/22\/how-can-i-display-a-hyperlink-in-a-message-box\/"},"modified":"2004-10-22T11:08:00","modified_gmt":"2004-10-22T11:08:00","slug":"how-can-i-display-a-hyperlink-in-a-message-box","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-display-a-hyperlink-in-a-message-box\/","title":{"rendered":"How Can I Display a Hyperlink in a Message Box?"},"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! Is it possible to have a hyperlink to a Web page in a message box?<BR><BR>&#8212; CB<\/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, CB. Sounds like you want to display a message box to users and, ideally, you\u2019d like to include a hyperlink they could click on for more information. For example, suppose a user tried to access some resource and was turned away. In a case like that, you could pop up a message box that tells them that access is denied, then provide them with a link to a Web page that tells them what they need to do to gain access. All in all a much nicer solution than simply telling them \u201cAccess Denied.\u201d<\/P>\n<P>So can you do this using a scripting language? Well, no, not as far as we know. Hyperlinks in message boxes would be very cool, but you\u2019re pretty much limited to rudimentary message boxes when using a scripting language.<\/P>\n<P>But wait, don\u2019t leave! You didn\u2019t ask us, \u201cIs there a workaround of some kind, something that does the same thing but doesn\u2019t embed a hyperlink in a message box?\u201d Had you asked us <I>that<\/I>, we would have said, \u201cHey, there\u2019s <I>always<\/I> a workaround of some kind.\u201d What you\u2019re looking for is one-click access to a Web page from a message box. One way to do that would be to embed a hyperlink in the message box; unfortunately, as we just noted, you\u2019re not going to do that with VBScript. So, let\u2019s try another way: why not pop up a message box that asks, \u201cDo you want to apply for access to this resource?\u201d If the user clicks <B>No<\/B>, the script terminates. If the user clicks <B>Yes<\/B>, then the script automatically takes them to the appropriate Web page. One message box, one-click access to a Web site. It\u2019s not <I>quite<\/I> the same as using a hyperlink, but the net result is identical.<\/P>\n<P>As you can see, this only takes a few lines of code:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)<\/p>\n<p>intMessage = Msgbox(&#8220;Would you like to apply for access to this resource?&#8221;, _\n    vbYesNo, &#8220;Access Denied&#8221;)<\/p>\n<p>If intMessage = vbYes Then\n    objShell.Run(&#8220;http:\/\/www.microsoft.com&#8221;)\nElse\n    Wscript.Quit\nEnd If\n<\/PRE>\n<P>We begin by creating an instance of the WSH Shell object; we\u2019ll need that in order to pop up a Web browser and connect to the Web site. We then display a message box (with the title <B>Access Denied<\/B>) that asks \u201cWould you like to apply for access to this resource?\u201d This message box has a <B>Yes<\/B> button and a <B>No<\/B> button, that\u2019s what the VBScript constant vbYesNo is there for.<\/P>\n<P><B>Note<\/B>. Some of you might be thinking, \u201cWait, I thought you had to explicitly define constants in VBScript.\u201d That\u2019s true in <I>most<\/I> cases; if we were working with the FileSystemObject, for example, we\u2019d need to define constants using code like this:<\/P><PRE class=\"codeSample\">Const ForReading = 1\n<\/PRE>\n<P>However, VBScript has some intrinsic constants of its own. vbYesNo is one; it\u2019s used to display a Yes button and a No button in a message box. vbCrLf is another; it\u2019s used to append a carriage return-linefeed to the end of a string. These intrinsic constants &#8211; which are part of the VBScript language &#8211; don\u2019t have to be defined; VBScript knows what you mean when you type vbYesNo.<\/P>\n<P>Now, where were we? Ah, yes, we pop up a message box and give the user <B>Yes<\/B> and <B>No<\/B> buttons. If the user clicks <B>Yes<\/B>, we\u2019re going to take them to the specified Web site. How do we know if they clicked <B>Yes<\/B>? That\u2019s easy: when we create the message box, we store the user\u2019s response in the variable intMessage. To determine which button the user clicked, we just check the value of intMessage. If the value is equal to vbYesNo (another intrinsic constant, equal to 6) then the user clicked <B>Yes<\/B>, and we use the Shell object\u2019s Run method to open the Web site http:\/\/www.microsoft.com. (Notice that all we have to do is specify the URL; the operating system then use the default browser to navigate to that site.) <\/P>\n<P>And what if the user clicks <B>No<\/B>? In that case, we just quit (Wscript.Quit). <\/P>\n<P>Like we said, not <I>exactly<\/I> what you had in mind, but it\u2019ll do the trick.<\/P>\n<P>Incidentally, if you\u2019d like to know more about VBScript\u2019s Msgbox function and the different ways you can configure it, check out this portion of the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/script56\/html\/vsfctMsgBox.asp\"><B>VBScript Language Reference<\/B><\/A> on MSDN.<\/P>\n<P>And what if you have a need to create <I>really<\/I> elaborate message boxes? Well, in that case, you could actually make yourself an HTML page and use that to mimic a true Windows message box. But that\u2019s a story we\u2019ll have to tell some other day.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is it possible to have a hyperlink to a Web page in a message box?&#8212; CB Hey, CB. Sounds like you want to display a message box to users and, ideally, you\u2019d like to include a hyperlink they could click on for more information. For example, suppose a user tried to access [&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,77],"class_list":["post-71163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-writing"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is it possible to have a hyperlink to a Web page in a message box?&#8212; CB Hey, CB. Sounds like you want to display a message box to users and, ideally, you\u2019d like to include a hyperlink they could click on for more information. For example, suppose a user tried to access [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71163","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=71163"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71163\/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=71163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}