我的vb脚本:saveGSheet.vbs(用于下载表格)在手动运行时工作正常。我想自动执行此操作,但自动任务不会下载该文件。
如何在任务计划程序中运行它?在 Windows Server 2008 上。
c:\Windows\SysWOW64\cscript saveGSheet.vbs
' Set your settings
strFileURL = "https://docs.google.com/spreadsheets/d/1B5jBWGHT1dGKCwE9KLTlFsyymNCc1s4AH1LcFQOcwqQ/export?format=xlsx"
strHDLocation = "C:\file.xlsx"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
'Response 200 is OK, now download sheet
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
注意:我不应该使用任何第三方应用程序,因此我不使用 wget。我按照建议制作了一个日志文件,结果:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\AppBackUpTools\ALM\NotifikaceVSE\SLA_Escalation\download_excel\saveGSheet.vbs(27, 3) ADODB.Stream: Write to file failed.
saveGSheet.bat如下:
c:\Windows\SysWOW64\cscript saveGSheet.vbs > %temp%\saveGSheet.log 2>&1
执行任务后,检查
%temp%\saveGSheet.log 中的日志文件内容,这应该会给您一些进一步调试的线索