Capture the URL of VBScript clipboard and open it in the browser

Source: Internet
Author: User
Tags blank page

Hello, cl. This is an interesting question, or we should say that it is two very interesting questions. Because you actually asked two questions. The first question is simple: Can I use a script to open a specific web site? You probably already know the answer. I can answer you out loud! The following is an example script that stores the URL of the script center in a variable named strurl. Then, this script creates an instance of the wsh shell object and uses the run method to open the default web browser and navigate to the specified URL:
Strurl = "http://www.microsoft.com/technet/scriptcenter/default.mspx"
Set objshell = Createobject ("wscript. Shell ")
Objshell. Run (strurl)
The second problem is tricky: Can I use a script to capture information from the clipboard? The answer to this question is "yes", although you must use a backdoor Program To the clipboard.
Neither wsh nor VBScript can interact with the clipboard: neither of them allows you to copy or paste data from the clipboard. On the other hand, Internet Explorer can interact with the clipboard. (Look, Internet Explorer is omnipotent !) So let ie do this for us. If you want to capture data from the clipboard, you can use Code Similar code:
Set objie = Createobject ("internetexplorer. application ")
Objie. navigate ("about: blank ")
Strurl = objie.doc ument. parentwindow. clipboardData. getdata ("text ")
Objie. Quit
Wscript. Echo strurl
What we do here is to create an Internet Explorer instance and open it on a blank page. Note that you cannot actually see this ie instance, because the visible attribute is not set to true. All things happen in the background.
Then, we use the clipboardData. getdata method to obtain the text placed on the clipboard and store it in the variable strurl. This is what the following line of code does:
Strurl = objie.doc ument. parentwindow. clipboardData. getdata ("text ")
We disable this ie instance (objie. Quit) and then echo the value we retrieved from the clipboard.
Try to copy some text to the clipboard and then run the script. You should get a message box containing the text you copied to the clipboard.
Now there is one thing to do: combine these two half scripts to form a complete script. The following script captures a URL from the clipboard and then opens the website in the default web browser:
Set objie = Createobject ("internetexplorer. application ")
Objie. navigate ("about: blank ")
Strurl = objie.doc ument. parentwindow. clipboardData. getdata ("text ")
Objie. Quit
Set objshell = Createobject ("wscript. Shell ")
Objshell. Run (strurl)
This script is not good enough. It also has an advantage-it is not only used to open web sites. Assume that your clipboard has a file path, such as "C: \ scripts \ scriptlog.txt ". Run this script to open the file in Notepad (or any application you set to be associated with the. txt file. If there is a path to the. DOC file on your clipboard, this script will open this document in Microsoft Word. It is actually a common file opening script, not just an open script that can only be used for web sites.

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.