Use VBScript to display a hyperlink in a message box _vbs

Source: Internet
Author: User
Tags constant
Ask:
Hey, scripting guy!. Can I include a hyperlink to a Web page in a message box?
--CB
For:
Hi, CB. It sounds like you want to display a message box to the user, and you want to include a hyperlink in the message box so that users can click on the link to get more information. For example, suppose a user tries to access some resources, but is rejected. In this case, you can pop up a message box, tell the user that access is denied, and then provide them with a link to the page that tells the user the permissions they need to access. Generally speaking, this approach would be much better than simply saying "access is denied".
So is it possible to do this with scripting language? Well, as far as we know, not yet. It's cool to have hyperlinks in a message box, but using scripting languages is limited to simple message boxes.
But wait, don't get busy leaving! You didn't ask us: "Is there a workaround for the same purpose, without having to embed the hyperlinks in the message box?" "If you ask, we'll tell you:" There's always a workaround. "What you're looking for is a one-click access to a Web page from a message box." One way to do this is to embed the hyperlinks in a message box, but unfortunately, as we've said above, using VBScript is not a good idea. So let's try something else to see: Why don't you pop up a message box and ask the user: "Do you want to apply for access to this resource?" "Then?" If the user clicks No, the script is aborted. If the user clicks Yes, the script will automatically bring the user to the appropriate Web page. A message box, one-click access to the Web site. It's not quite the same as using hyperlinks, but the result is the same.
As you can see, this only requires the following lines of code:
Copy Code code as follows:

Set Objshell = CreateObject ("Wscript.Shell")
Intmessage = Msgbox ("Would" to apply for access to this resource? ", _
vbYesNo, "Access Denied")
If intmessage = vbyes Then
Objshell.run ("http://www.microsoft.com")
Else
Wscript.Quit
End If
We first create a WSH Shell object instance; We need to create this instance to pop up a Web browser and link to a Web site. We then display a message box (titled Access Denied) and ask the user: "Do you want to apply for access to this resource?" "This message box has a button and a No button, which is the purpose of the VBScript constant vbYesNo."
Note: Some people may be thinking, "Wait, I think you should explicitly define these constants in VBScript." "In most cases, that's right. If we are dealing with FileSystemObject (for example), then we need to define constants like the following code:
Const ForReading = 1
However, VBScript has some intrinsic constants. vbYesNo happens to be one of them. It is used to display the Yes button or no button in a message box. VbCrLf is another intrinsic constant that adds a carriage return line to the end of the string. These internal constants--which are part of the VBScript language--do not have to be defined; VBScript will know what you mean when you enter vbYesNo.
What were we talking about? Oh, yes, we pop up a message box and provide the user with a button and no button. If the user clicks Yes, we take them to the specified site. So how do you know if the user clicked on it? It's simple: when we create a message box, we store the user response in the variable intmessage. Therefore, to determine which button the user has clicked, we just need to check the value of the intmessage. If this value equals vbYesNo (another intrinsic constant, equal to 6), then the user clicks on it, so we use the Shell object's Run method to open the site http://www.microsoft.com. (Note that all we need to do is specify the URL; then the operating system navigates to the site using the default browser.) )
What if the user clicks on it? In this case, we will exit (Wscript.Quit).
As we say, this method is not exactly the same as we imagined, but it can accomplish this.
By the way, if you want more information about the Msgbox function of VBScript and the different ways to configure this function, visit the VBScript Language Reference on MSDN.
What if you need to make a nice little message box? In this case, you can create an HTML page yourself, and then use this page to simulate a real Windows message box. However, we will discuss this issue at other times.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.