2017-08-12 54 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 
相關問題