2017-08-12 68 views
0

我运行下面的VBScript程序,download.vbs如何解决VBScript中的文件下载路径错误?

dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP") 
dim bStrm: Set bStrm = createobject("Adodb.Stream") 
xHttp.Open "GET", "http://websitelink/textfile.txt", False 
xHttp.Send 

with bStrm 
.type = 1 '//binary 
.open 
.write xHttp.responseBody 
.savetofile "c:\dump.txt", 2 '//overwrite 
end with 
这个计划

,它会下载从指定的Web网址的文本文件并将其保存到本地磁盘中给定的路径。

但问题是,它的运作良好时,我当我使用本地磁盘c:的下载路径更改下载路径到本地磁盘d:

,并显示以下错误。

VBScript中的错误信息,

Script:  C:\test\download.vbs 
Line:  10 
Char:  5 
Error:  Write to file failed. 
Code:  800A0BBC 
Source:  ADODB.Stream 

请帮助。我会非常感谢。

+1

您必须具有管理员权限才能复制到OS驱动器! – GTAVLover

+0

[尝试运行提升的脚本](https://www.google.com/search?q=site%3Astackoverflow.com+vbs+elevated)。 – omegastripes

回答

0

如果文件不存在 - 您想在safetofile上使用1。您可以添加一些代码

Const AdTypeBinary = 1, AdTypeText = 2 
Const FsoRead = 1, FsoWrite = 2, FsoAppend = 8 
Const BstrmCreate = 1, BstrmOvrWrt = 2 
dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject") 
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP") 
dim bStrm: Set bStrm = createobject("Adodb.Stream") 
xHttp.Open "GET", "http://websitelink/textfile.txt", False 
xHttp.Send 
mysavefile = "D:\dump.txt" 'Set your save-file here 



with bStrm 
    .type = AdTypeBinary ' YOU MAY WANT TO CHANGE FILE TYPE FOR TEXT/BINARY 
    .open 
    .write xHttp.responseBody 

    if (FSO.FileExists(mysavefile)) then 
     .savetofile mysavefile, BstrmCreate 
    else 
     .savetofile mysavefile, BstrmOvrWrt 
    end if 
end with 
相关问题