木子屋 Dnawo's BLOG

用VBS可执行程序+Xmlhttp下载网络文件

👤 dnawo 📅 2006-07-27 👁 6269 👍 0 💬 0 🔄 来源:网络
'On Error Resume Next
Dim iRemote,iLocal
iRemote = InputBox("请输入远程文件路径:")
Set xPost = CreateObject("Microsoft.XMLHTTP")
xPost.Open "GET",iRemote,0
xPost.Send()
Set stream = CreateObject("ADODB.Stream")
stream.Mode = 3
stream.Type = 1
stream.Open()
stream.Write(xPost.responseBody)
if (stream.size<10240) then
MsgBox("远程文件不存在!")
else
SaveFile
end if
stream.close
set stream = nothing

' 保存文件
function SaveFile
iLocal = InputBox("请输入本机保存路径:")
Set fso = CreateObject("Scripting.FileSystemObject")
returnValue = "0"
if (fso.FileExists(iLocal)) then
returnValue = MsgBox("'"&iLocal&"'文件已存在,真的要覆盖吗?",vbYesNoCancel,"确认框")
end if
set fso = nothing
if (returnValue = "6" or returnValue = "0") then '覆盖
stream.SaveToFile iLocal,2
MsgBox("文件备份成功!")
elseif (returnValue = "7") then
SaveFile
end if
end function
保存为VBS后缀的文件,直接双击运行就可以了。

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 开始-运行-命令大全 下一篇 → 网页中Flash播放器常用参数设置