无法写入文件错误 - ADODB.stream

Failed to write to file error - ADODB.stream

我想使用 .vbs 文件从 Internet 下载文件。我在这里得到代码:Is it possible to download using the Windows command line?

它使用ADODB.stream将文件解压到我的C盘。我 运行 它在 Windows XP SP3 上运行良好。然后当我在 Windows 10 上尝试 运行 它时,我得到了 "could not write to file" 错误。我也在 CMD 中用 "cscript.exe download.vbs" 尝试过,同样的事情发生了。 Windows XP 和 Windows 10 之间有什么区别会导致此错误?可以修复吗?

这里是确切的代码:

strFileURL = "http://www.it1.net/images/it1_logo2.jpg"
strHDLocation = "c:\logo.jpg"
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0    
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing

虽然这可能看起来是一个编程问题,但实际上与操作系统直接相关。您在 Windows XP 和 Windows 10 之间遇到的变化被称为 User Account Control (首先在 Windows Vista 中引入)

How do I get permissions to save in a folder that Windows 7 denies me from?

所述

This is due to UAC (User Access/Account Control) On Windows Vista / 7, and trying to write to a protected folder.

在Windows10系统驱动器的根目录(通常是安装OS的驱动器)被归类为受保护的文件夹。

访问受保护的文件夹需要更高的权限,当 运行 VBScript 通过 Windows 脚本宿主时,可以通过在管理员模式下启动命令提示符 (可从程序上下文中获得)来完成menu) 并使用所需的脚本路径调用 wscript.execsscript.exe