返回列表 发帖
powershell对多线程有限制,用curl.exe --parallel更快
  1. Add-Type -Path .\Downloader.dll
  2. $url_WX = "https://dldir1v6.qq.com/weixin/Windows/WeChatSetup.exe" #微信
  3. $url_QQ = "https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x64_01.exe" #QQ
  4. $url_TIM = "https://dldir1.qq.com/qqfile/qq/TIM3.5.0/TIM3.5.0.22143.exe" #TIM
  5. # 创建 DownloadConfiguration 实例并设置属性
  6. $downloadConfig = [Downloader.DownloadConfiguration]@{
  7.     ChunkCount       = 4
  8.     ParallelDownload = $true
  9. }
  10. #  创建DownloadService
  11. $downloadService = [Downloader.DownloadService]::new($downloadConfig)
  12. # Register object event listener
  13. Register-ObjectEvent -InputObject $downloadService -EventName DownloadProgressChanged -SourceIdentifier downloadService.DownloadProgressChanged -Action {
  14.     #$EventArgs.ProgressPercentage|Out-Host
  15.     $percent = [Math]::Truncate($EventArgs.ProgressPercentage * 100) -as [int]
  16.     Write-Progress -Activity "downloading:$($EventArgs.ProgressId)" -Status ("{0:F0}% Completed:" -f $percent) -Id 2 -PercentComplete $percent -CurrentOperation $EventArgs.ProgressId
  17. }
  18. Register-ObjectEvent -InputObject $downloadService -EventName ChunkDownloadProgressChanged  -SourceIdentifier downloadService.ChunkDownloadProgressChanged  -Action {
  19.     #$EventArgs.ProgressPercentage|Out-Host
  20.     $percent = [Math]::Truncate($EventArgs.ProgressPercentage * 100) -as [int]
  21.     Write-Progress -Activity "downloading:$($EventArgs.ProgressId)" -Status ("{0:F0}% Completed:" -f $percent) -ParentId 2 -PercentComplete $percent -CurrentOperation $EventArgs.ProgressId
  22. }
  23. # 下载tim.exe
  24. $task1 = $downloadService.DownloadFileTaskAsync($url_TIM, ".\download\tim.exe")
  25. $awaiter = $task1.GetAwaiter()
  26. while (-not $awaiter.IsCompleted) { Start-Sleep -Milliseconds 200; }
  27. Unregister-Event -SourceIdentifier *
复制代码
微信:flashercs
QQ:49908356

TOP

回复 7# 小白龙

powershell进度条不是控制台字符,而是图形化的.
微信:flashercs
QQ:49908356

TOP

回复 10# 小白龙
  1. # curl.exe路径,7.76+才支持--parallel
  2. $curl = "curl.exe"
  3. # 定义文件的URL和保存路径
  4. $downloads = @(
  5.   @{
  6.     src  = "https://dldir1.qq.com/qqfile/qq/TIM3.5.0/TIM3.5.0.22143.exe"
  7.     dest = "$home\downloads\tim.exe"
  8.   }
  9.   @{
  10.     src  = "https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x64_01.exe"
  11.     dest = "$home\downloads\qq.exe"
  12.   }
  13. )
  14. $begin = $true
  15. $downloads | ForEach-Object {
  16.   if ($begin) {
  17.     $begin = $false
  18.   } else {
  19.     '--next'
  20.   }
  21.   '--url "{0}"' -f $_.src
  22.   '--output "{0}"' -f ($_.dest.Replace('\', '\\'))
  23.   '--location'
  24.   '--compressed'
  25.   '--tr-encoding'
  26.   '--globoff'
  27. } -End {
  28.   '--parallel'
  29. } | & $curl --config -
复制代码
微信:flashercs
QQ:49908356

TOP

回复 18# 小白龙
  1. if($LASTEXITCODE -ne 0)
复制代码
微信:flashercs
QQ:49908356

TOP

返回列表