I'm about to be forced to write a script to download some number of files under Windows XP. The machines the script will be run at are all behind a proxy, and the proxy settings are entered into the IE configuration.
What came to my mind was either to somehow call IE from the command line, and using its configuration download files I'd need. Is it even possible using some shell-techniques?
Other option would be to use wget
under Win, but I'd need to pass the proxy-settings to it. How to recover those settings from IE configuration?
In principle, I would go for the wget
approach rather than using IE
in some way.
The path to the configuration script is stored in the registry in HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings
. It is a binary value, the script address starts at position 0x18 and seems ASCII encoded.
What I don't know is if wget
can evaluate the script by itself, or if you need to parse it explicitly in your script that would then pass the proxy address to wget
.
I agree with Treb you should prefer using wget and the path to the proxy settings can be found in "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
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.