views:

235

answers:

3

Hey,

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?

+1  A: 

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.

Treb
+1  A: 

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"

SDX2000
The path in the regsitry you give does not exist on my computer - maybe it depends on the IE version, I am using IE 6.0
Treb
Hi I have IE 7 on my machine but I vaguely remember using this path on a machine with IE 6.
SDX2000
wait I made this post from another computer and it has IE 6
SDX2000
+1  A: 

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.

Grant Wagner