Q:
Hi, scripting guy! Can I include a hyperlink to a web page in the message box?
-- CB
A:
Hi, CB. It sounds like you want to display a message box to the user and want to include a hyperlink in the message box so that the user can click this link for more information. For example, assume that a user attempts to access some resources but is denied. In this case, you can pop up a message box to tell the user that the access is denied and then provide them with a link. The page to which the link points will tell the user the required permissions to access. In general, this approach is much better than simply saying "access is denied.
Can I use a scripting language to achieve this purpose? Well, as far as we know, it's not yet possible. The message box containing hyperlinks is certainly cool, but the scripting language is limited to simple message boxes.
But wait. Don't leave! You didn't ask us: "Is there a way to achieve the same purpose, but you don't have to embed a hyperlink in the message box ?" If you ask this question, we will tell you: "There will always be a work und ." What you are looking for is a one-click access to the web page from the message box. One method is to embed a hyperlink in the message box. Unfortunately, as we have mentioned above, using VBScript cannot achieve the above purpose. Therefore, we try another way to see why a message box does not pop up, asking the user: "do you want to apply for access to this resource ?" What about it? If you click NO, the script is aborted. If you click yes, the script automatically takes the user to the appropriate web page. A message box allows you to access the website with one click. It is different from the hyperlink, but the result is the same.
As you can see, this only requires the following lines
Code You can achieve the following:
Copy code The Code is as follows: Set objshell = Createobject ("wscript. Shell ")
Intmessage = msgbox ("wocould you like 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
First, create a wsh shell object instance. We need to create this instance to bring up a Web browser and link to the website. Then, we will 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 "yes" button and a "no" button, which is the purpose of the VBScript constant vbyesno.
Note: Some may think: "Wait, I think you should define these constants in VBScript ." In most cases, this is correct. If we are dealing with FileSystemObject (for example), we need to use code similar to the following to define constants:
Const forreading = 1
However, VBScript has some internal constants. Vbyesno is exactly one of them. It is used to display the "yes" button or "no" button in the message box. Vbcrlf is another internal constant, which is used to add a carriage return to the end of the string to wrap the line. These internal constants-they are part of the VBScript language-do not need to be defined; when you input vbyesno, VBScript will know what you mean.
Where did we talk about? By the way, a message box is displayed, and the "yes" and "no" buttons are provided to users. If you click yes, we will take them to the specified website. So, how do I know if the user clicks yes? 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 only need to check the intmessage value. If this value is equal to vbyesno (another internal constant, equal to 6), the user clicks yes, so we use the run method of the shell object to open the website http://www.microsoft.com. (Note: what we need to do is to specify the URL, and then the operating system will use the default browser to navigate to the site .)
If the user clicks "no? In this case, we will exit (wscript. Quit ).
As we said, this method is not exactly the same as we thought, but it can achieve this purpose.
By the way, if you want to learn more about the msgbox function of VBScript and the different methods for configuring this function, visit "VBScript language reference" on msdn ".
What if you want to create a message box? In this case, you can create an HTML page and use it to simulate a Windows message box. However, we will discuss this issue at other times.