Click here to Skip to main content
15,881,715 members
Articles / Web Development / HTML
Article

SmartDownloadManager

Rate me:
Please Sign up or sign in to vote.
2.73/5 (5 votes)
15 May 20073 min read 39.8K   960   25   3
Create download managers using VBScript

Screenshot - SmartDownloadManager1.gif

Screenshot - SmartDownloadManager2.gif

Introduction

This article gives some basic information about how to create your own download managers.

Procedure

There are four different steps that must be followed for the application to work. They are:

  1. Adding your own item to the Right Click menu of Internet Explorer.
  2. Gathering required information from the Page using VBScript files, Javascript files or HTML files when the user clicks the added item.
  3. Launching the main application that does the actual downloading.
  4. Programming the main application to download the target file.

Step 1: Adding our own item to the Right Click menu of the Internet Explorer

Internet Explorer offers a built-in registry key to enable the addition of new menu items to the right click menu.

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt

Adding a new subkey to the above key will show a new item in the right click menu of Internet Explorer. Let us add a new key called "Download Now." We have to add the path of a script file to the default value of the key. Internet Explorer launches the script file when the item is clicked.

Step 2: Gathering required information from the Page

The script file should gather information such as the URL, the element which the user right clicked, and so on. This file is launched when the user selects the added item.

VBScript
var path = document.location.pathname;
var Exepath = path.replace("SmartDownloadManager.htm",
    "SmartDownloadManager.exe");
var Doc   = external.menuArguments.document;
var Event = external.menuArguments.event;
var mainURL   = external.menuArguments.document.URL;
var Element = Doc.elementFromPoint(Event.clientX, Event.clientY);
var Anchor  = Element;
var cookie = Doc.cookie;
while( Anchor.tagName!="A" && Anchor.tagName!="HTML" )
{
    Anchor = Anchor.parentElement;
}

if(Anchor.tagName=="A")
{
    lnkURL  = Anchor.href;
    var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun = Exepath;
    oShell.ShellExecute(commandtoRun,
        "\""+mainURL+"\"" + " \"" + cookie+"\" \"" + lnkURL + "\"","",
        "open", "1");
}

The above code retrieves the element on which the user has made the right click and stores the reference in the variable Element. A simple while loop is used to check whether the anchor tag has any nested tags, like images, or any other formatting tags. Finally, a simple if condition checks whether the user has chosen the anchor tag or the blank page. It launches the application and passes the required information to the application as command line arguments.

Step 3: Launching the main application

VBScript
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute(commandtoRun, "\""+mainURL+"\""
    + " \"" + cookie+"\" \"" + lnkURL + "\"","", "open", "1");

The above code launches the main application which does the actual downloading and passes such information as: main page URL, the URL of the link, etc.

Step 4: Programming tha main application to download the target file

VBScript
static void Main(string[] args)

The arguments that are supplied in Step 3 are stored in the array args of the Main function. Using these arguments, we can easily create a program that downloads the target file. A lot of articles can be found on this topic on the CodeProject.com website itself.

Conclusion

Copy the executable folder into any location. There is a file called SetUp.exe in the executable folder. This file has to be executed for the first time and will create proper registry values. Once the file is executed, the location of the files should not be changed, as it will not work properly. If the location of the folder gets changed, the registry of Download Now has to be manually deleted. After deleting the registry, you can safely execute SetUp.exe again to make the new registry values.

History

  • 15 May, 2007 - Original version posted

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Chronus Corporation
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to insert a menu when right click blank place? Pin
hays.zhao6-Jun-07 21:31
hays.zhao6-Jun-07 21:31 
For example:
when right click blank place of desktop or an opened explorer, a menu will appear.
it contain "view"
"Arrange Icons By"
"Paste"
"Paste Shortcut"
"New"
"Properties" and ...

now i want to insert a menu like "Paste", how can do it?

I know that how to insert a menu to right click menu of a file or folder as you introduced.

string keyname = "Reg Paste";
string guid = "{" + typeof(PasteMenu).GUID.ToString() + "}";
RegistryKey rk, rk2;
rk = Registry.ClassesRoot.OpenSubKey(@"xmlfile\shellex\ContextMenuHandlers", true);
rk2 = rk.OpenSubKey(keyname);
if (rk2 == null)
rk2 = rk.CreateSubKey(keyname);
rk2.SetValue("", guid);
rk2.Close();
rk.Close();

But how to registry to blank place of window?

Thanks very much if you can give me same advice!


take it easy & keep it simple....

Questionmissing details Pin
thompsonson223-May-07 1:06
thompsonson223-May-07 1:06 
AnswerRe: missing details Pin
Arun.Immanuel23-May-07 4:07
Arun.Immanuel23-May-07 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.