简体   繁体   English

Windows下脚本文件下载

[英]scripted files download under Windows

I'm about to be forced to write a script to download some number of files under Windows XP. 我将被迫编写脚本以在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. 将在其上运行脚本的计算机都位于代理之后,并将代理设置输入到IE配置中。

What came to my mind was either to somehow call IE from the command line, and using its configuration download files I'd need. 我想到的是要么以某种方式从命令行调用IE,然后使用我需要的配置下载文件。 Is it even possible using some shell-techniques? 甚至有可能使用某些Shell技术吗?

Other option would be to use wget under Win, but I'd need to pass the proxy-settings to it. 另一个选择是在Win下使用wget ,但是我需要将代理设置传递给它。 How to recover those settings from IE configuration? 如何从IE配置中恢复这些设置?

In principle, I would go for the wget approach rather than using IE in some way. 原则上,我会选择wget方法,而不是以某种方式使用IE

The path to the configuration script is stored in the registry in HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections\\DefaultConnectionSettings . 配置脚本的路径存储在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. 它是一个二进制值,脚本地址从位置0x18开始,似乎是ASCII编码的。

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 . 我不知道wget可以自己评估脚本,或者是否需要在脚本中显式解析脚本,然后将代理地址传递给wget

我同意Treb,您应该更喜欢使用wget,并且可以在“ HKCU \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Internet Settings \\ ProxyServer”中找到代理设置的路径。

Use JScript: 使用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 . 然后,使用start download.jscscript download.js调用它。 You can do something similar with VBScript, but I'm more comfortable in JScript. 您可以使用VBScript做类似的事情,但是我对JScript感到更舒服。

Note that this ONLY works if the target of the ie.Navigate() is a file that prompts for Open/Save/Cancel. 请注意,仅当ie.Navigate()的目标是提示打开/保存/取消的文件时,此方法才有效。 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. 如果浏览器中打开的是PDF之类的文件类型,则IE只会打开资源,然后关闭窗口,可能不是您想要的。 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. 显然,您可以根据自己的需要调整脚本,例如在下载完成后不关闭IE窗口,或者放大窗口等。

See the InternetExplorer Object documentation for more information about the Events, Methods and Properties available. 有关可用的事件,方法和属性的更多信息,请参见InternetExplorer对象文档

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. 使用此方法,您不必担心读取Internet Explorer的代理设置,因为您正在使用Internet Explorer进行下载,所以将使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM