Use JScript:
function ie_NavigateComplete2(pDisp, url)
{
// output for testing
WScript.Echo('navigation to', url, 'complete');
// clear timer
t = 0;
}
// create ActiveX object
var ie = WScript.CreateObject('InternetExplorer.Application', 'ie_');
ie.Height = 200;
ie.Width = 200;
ie.Visible = true;
ie.Navigate('http://www.example.com/worddoc.doc');
var t = (+new Date()) + 30000;
// sleep 1/2 second for 30 seconds, or until NavigateComplete2 fires
while ((+new Date()) < t)
{
WScript.Sleep(500);
}
// close the Internet Explorer window
ie.Quit();
Then you invoke it with start download.js
or cscript download.js
. You can do something similar with VBScript, but I'm more comfortable in JScript.
Note that this ONLY works if the target of the ie.Navigate()
is a file that prompts for Open/Save/Cancel. If it is a file type such as PDF that opens inside the browser, then IE will simply open the resource, then close the window, probably not what you want. Obviously you could adjust the script to suit your needs, such as not closing the IE window when the download is complete, or making the window larger, etc.
See the InternetExplorer Object documentation for more information about the Events, Methods and Properties available.
Using this method, you don't have to worry about reading the proxy settings for Internet Explorer, they will be used because you are using Internet Explorer to do the download.