我有this个VBS用于下载文件:
Set args = Wscript.Arguments
downloadURL = WScript.Arguments.Item(0)
saveLocation = WScript.Arguments.Item(1)
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", downloadURL, False
xHttp.Send
with bStrm
.type = 1 '//binary
.open
.write xHttp.responseBody
.savetofile saveLocation, 2 '//overwrite
end with
和这个批处理文件(pastebin),它应该下载一堆文件并解压缩压缩文件:
@echo off
setlocal EnableDelayedExpansion
rem Set the output directory
set output=Plugins
rem Set the directory name that will be used when unzipping files
set zip_temp=Temp
rem set the path to the download vbs
set dl_vbs=Resources\dl.vbs
rem Set the name for the zip extractor VBS
set zip_vbs=Resources\extract.vbs
rem set date_time to Year-Month-Day_HourH-MinuteM
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set DATETIME_VAR=%%j
set date_time=%DATETIME_VAR:~0,4%-%DATETIME_VAR:~4,2%-%DATETIME_VAR:~6,2%_%DATETIME_VAR:~8,2%H-%DATETIME_VAR:~10,2%M
echo Deleting old log files...
rem Remember to keep this updated with %date_time%!
del Log_*-*-*_*H-*M.txt
echo Done.
echo.
rem Set the log file name
set log=Log_%date_time%.txt
> %log% echo -- Log --
>>%log% echo.
rem Empty the output folder
echo Deleting + replacing output (%output%)...
if NOT "%output%"=="." (
if exist %output% rd /s /q %output%
md %output%
)
echo Done.
>>%log% echo Output folder "%output%" Deleted and remade.
>>%log% echo.
echo.
rem Could be latest verison (latest) or beta version (beta). Or, release version (release).
rem ( See: https://bukkit.org/threads/uniform-links-to-latest-version.118175/ post #10 )
set type=latest
rem Start the counter at 1
set /a plugin_counter=1
rem download_index = word used in the URL for downloading the file
rem desired_name = name of the plugin; name of the finished downloaded file
rem download_location = an alternate URL if the global one doesn't work
rem zip_location = the name of the jar file in the zip if the download file is a zip rather than jar
rem plugin_disabled_reason = the reason that this particular plugin is not to be downloaded at all
set download_index[!plugin_counter!]=afkterminator
set desired_name[!plugin_counter!]=AFK-Terminator
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=autorefill
set desired_name[!plugin_counter!]=AutoRefill
set zip_location[!plugin_counter!]=AutoRefill.jar
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=autosaveworld
set desired_name[!plugin_counter!]=AutoSaveWorld
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=compatnocheatplus-cncp
set desired_name[!plugin_counter!]=CompatNoCheatPlus
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=commandlog
set desired_name[!plugin_counter!]=CommandLog
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=coreprotect
set desired_name[!plugin_counter!]=CoreProtect
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=cshortcut
set desired_name[!plugin_counter!]=C-Shortcut
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=deathcontrol
set desired_name[!plugin_counter!]=DeathControl
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=disable-respawn-screen
set desired_name[!plugin_counter!]=DisableRespawnScreen
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=dropswap
set desired_name[!plugin_counter!]=DropSwap
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=emp
set desired_name[!plugin_counter!]=EnjinMinecraftPlugin
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=essentials
set desired_name[!plugin_counter!]=Essentials
set zip_location[!plugin_counter!]=target\*
set download_location[!plugin_counter!]=https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/Essentials/target/*zip*/target.zip
set /a plugin_counter+=1
set download_index[!plugin_counter!]=essentialschat
set desired_name[!plugin_counter!]=EssentialsChat
set zip_location[!plugin_counter!]=target\*
set download_location[!plugin_counter!]=https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/EssentialsChat/target/*zip*/target.zip
set /a plugin_counter+=1
set download_index[!plugin_counter!]=essentialsspawn
set desired_name[!plugin_counter!]=EssentialsSpawn
set zip_location[!plugin_counter!]=target\*
set download_location[!plugin_counter!]=https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/EssentialsSpawn/target/*zip*/target.zip
set /a plugin_counter+=1
set download_index[!plugin_counter!]=factions
set desired_name[!plugin_counter!]=Factions
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=frameprotect
set desired_name[!plugin_counter!]=FrameProtect
set download_location[!plugin_counter!]=bukget
set zip_location[!plugin_counter!]=FrameProtect.jar
set /a plugin_counter+=1
set download_index[!plugin_counter!]=frameprotect
set desired_name[!plugin_counter!]=FrameProtectDatabaseUpdater
set download_location[!plugin_counter!]=bukget
set zip_location[!plugin_counter!]=FrameProtectDatabaseUpdater.jar
set /a plugin_counter+=1
set download_index[!plugin_counter!]=global-market
set desired_name[!plugin_counter!]=GlobalMarket
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=insanemobs
set desired_name[!plugin_counter!]=InsaneMobs
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=magicloot
set desired_name[!plugin_counter!]=MagicLoot
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=mcore
set desired_name[!plugin_counter!]=MassiveCore
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=mcmmo
set desired_name[!plugin_counter!]=mcMMO
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=modifyworld
set desired_name[!plugin_counter!]=ModifyWorld
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=multiverse-core
set desired_name[!plugin_counter!]=MultiverseCore
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=multiverse-inventories
set desired_name[!plugin_counter!]=MultiverseInventories
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=multiverse-netherportals
set desired_name[!plugin_counter!]=MultiverseNetherPortals
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=multiverse-portals
set desired_name[!plugin_counter!]=MultiversePortals
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=multiverse-teleportfilter
set desired_name[!plugin_counter!]=MultiverseTeleportFilder
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=nobreeding
set desired_name[!plugin_counter!]=NoBreeding
set download_location[!plugin_counter!]=bukget
set plugin_disabled_reason[!plugin_counter!]=Inactive project; no updates.
set /a plugin_counter+=1
set download_index[!plugin_counter!]=nocheatplus
set desired_name[!plugin_counter!]=NoCheatPlus
set download_location[!plugin_counter!]=jenkins
set /a plugin_counter+=1
set download_index[!plugin_counter!]=ontime
set desired_name[!plugin_counter!]=OnTime
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=openinv
set desired_name[!plugin_counter!]=OpenInv
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=permissionsex
set desired_name[!plugin_counter!]=PermissionsEx
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=perworldplugins
set desired_name[!plugin_counter!]=PerWorldPlugins
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=plotme
set desired_name[!plugin_counter!]=PlotMe
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=plotme-defaultgenerator
set desired_name[!plugin_counter!]=PlotMeDefaultGenerator
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=protocollib
set desired_name[!plugin_counter!]=ProtocolLib
set download_location[!plugin_counter!]=jenkins
set /a plugin_counter+=1
set download_index[!plugin_counter!]=ptweaks-remove-all-server-lag
set desired_name[!plugin_counter!]=pTweaks
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=pvpmanager
set desired_name[!plugin_counter!]=PvP-Manager
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=pwnplantgrowth
set desired_name[!plugin_counter!]=pwnPlantGrowth
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=signedit
set desired_name[!plugin_counter!]=SignEdit
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=simplesort
set desired_name[!plugin_counter!]=SimpleSort
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=tjp
set desired_name[!plugin_counter!]=TheJoyOfPainting
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=toolswap
set desired_name[!plugin_counter!]=ToolSwap
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=treeassist
set desired_name[!plugin_counter!]=TreeAssist
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=vault
set desired_name[!plugin_counter!]=Vault
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=voxelsniper
set desired_name[!plugin_counter!]=VoxelSniper
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=whatisit
set desired_name[!plugin_counter!]=WhatIsIt
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=worldedit
set desired_name[!plugin_counter!]=WorldEdit
set download_location[!plugin_counter!]=bukget
set /a plugin_counter+=1
set download_index[!plugin_counter!]=worldguard
set desired_name[!plugin_counter!]=WorldGuard
set download_location[!plugin_counter!]=bukget
echo ---- Beginning downloads ----
echo.
rem for every plugin with var %%p being the number of the plugin
rem for all *_c variables, the c stands for current
rem %%p, p for plugin!
for /l %%p in (1,1,!plugin_counter!) do (
if defined zip_location[%%p] (
set file_name_c=!desired_name[%%p]!.zip
set file_type_c=zip
) else (
set file_name_c=!desired_name[%%p]!.jar
set file_type_c=jar
)
rem Try downloading 3 times.
for /l %%n in (1,1,3) do (
rem If the file has not been downloaded.
if not exist "%output%\!file_name_c!" (
rem If it's the first try, the download didn't fail -- it's just the first try.
if %%n==1 (
echo Downloading !desired_name[%%p]!
echo Downloading !file_name_c!>>%log%
rem If it's the second try or later, the download failed and we are retrying
) else (
echo Download failed. Retrying...
echo Download failed. Retrying...>>%log%
)
if !download_location[%%p]!==bukget (
cscript //nologo %dl_vbs% "https://api.bukget.org/3/plugins/bukkit/!download_index[%%p]!/%type%/download" "%output%\!file_name_c!"
)
if !download_location[%%p]!==jenkins (
cscript //nologo %dl_vbs% "http://ci.md-5.net/job/!download_index[%%p]!/lastSuccessfulBuild/artifact/target/!file_name_c!" "%output%\!file_name_c!"
) else (
cscript //nologo %dl_vbs% "!download_location[%%p]!" "%output%\!file_name_c!"
)
)
)
rem If the file STILL doesn't exist, the download failed.
if not exist "%output%\!file_name_c!" (
echo Could not download.
echo Could not download.>>%log%
rem If it didn't fail, continue.
) else (
rem If it's a zip file, we need to unzip it.
if defined zip_location[%%p] (
rem Try unzipping 3 times.
for %%n in (1,1,3) do (
rem If it's the first try, the unzip attempt didn't fail -- it's just the first try.
if %%n==1 (
echo Unzipping !desired_name[%%p]!
echo Unzipping !file_name_c!>>%log%
rem If it's the second try or later, the unzip attempt failed and we are retrying
) else (
echo Unzipping failed. Retrying...
echo Unzip attempt failed. Retrying...>>%log%
)
rem If we have not successfully unzipped
if not exist "%output%\!desired_name[%%p]!.jar" (
rem Make a temporary folder to unzip to.
md %zip_temp%
rem Unzip the plugin to the temporary folder
cscript //nologo %zip_vbs% "%cd%\%zip_temp%\" "%cd%\%output%\!file_name_c!"
rem Move the file we need to another folder (we need this for files we don't know the names of)
md "%zip_temp%\final"
move "%zip_temp%\!zip_location[%%p]!" "%zip_temp%\final\"
rem Rename file to the desired name
ren "%zip_temp%\final\*.jar" "!desired_name[%%p]!.jar"
rem Move the file to the output directory
move "%zip_temp%\final\!desired_name[%%p]!.jar" "%output%\"
rem Delete the temporary folder
rd /s /q %zip_temp%
rem Delete the original zip file
del /q "%output%\!file_name_c!"
)
)
)
)
echo.
echo.>>%log%
)
rem If getting "Access denied" when trying to run this batch, see here -- the internet-security-options-related answer: https://stackoverflow.com/questions/17401413/msxml3-dll-access-denied
endlocal
使用批处理文件会按预期输出,但VBS(larger image)出错:
文件按预期下载,所以我有两个问题:
这有点令人困惑,因为这个错误永远不会出现在the other batch file I use for this上,它的目的是完全相同的。
注意:如果我尝试使用dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP.6.0")
,我会收到此VBS错误:dl.vbs(6, 12) Microsoft VBScript runtime error: ActiveX component can't create object: 'Microsoft.XMLHTTP.6.0'
另一个注意事项:我不知道如何编写VBS代码。因此,我不会理解技术性。请尽量保持简单的答案,并记住我正在寻找答案,而不是解释 - 只是因为我不理解它们。
感谢您的帮助:]
答案 0 :(得分:0)
原来错误意味着我正在尝试使用无效的网址下载。
但下载工作正常。
这是一个问题:我有三类下载:
而不是使用:
If (want x service):
downloadFrom.service(x)
Elif (want y service):
downloadFrom.service(y)
Else
downloadFrom.service(custom)
我一直在使用:
If (want x service):
downloadFrom.service(x)
If (want y service):
downloadFrom.service(y)
Else
downloadFrom.service(custom)
如果If (want x service)
= true
,它将从服务x和自定义服务下载。
感谢@SomethingDark带领我找到这个解决方案!