[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 3# Five66


    我脑子更不好使, 完全看不懂, 大佬如果懂原理, 用gpt估计能搞出来, 我不行, gpt不听我使唤

TOP

回复 2# flashercs
用 curl.exe --parallel  在gpt中死活就是搞不成功, ai还是太弱智了, 哎
  1. # 定义文件的URL和保存路径
  2. $urls = @(
  3.     "https://dldir1v6.qq.com/weixin/Windows/WeChatSetup.exe",
  4.     "https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x64_01.exe",
  5.     "https://dldir1.qq.com/qqfile/qq/TIM3.5.0/TIM3.5.0.22143.exe"
  6. )
  7. # 获取桌面路径
  8. $desktop = [System.Environment]::GetFolderPath('Desktop')
  9. # 使用 curl.exe 并行下载,重定向输出到 $null 以避免 PowerShell 处理输出内容
  10. & curl.exe --parallel `
  11.     --output "$desktop\WeChatSetup.exe" $urls[0] `
  12.     --output "$desktop\QQ_9.9.15.exe" $urls[1] `
  13.     --output "$desktop\TIM3.5.0.exe" $urls[2] `
  14.     *> $null
复制代码

TOP

回复 2# flashercs

多谢大佬, powershell不是支持并行处理吗?
我用gpt生成了如下代码, 能执行成功, 但是没有进度条, 发现gpt还是不够智能, N多轮才能搞成
  1. # 定义文件的URL和保存路径
  2. $urls = @(
  3.     "https://dldir1v6.qq.com/weixin/Windows/WeChatSetup.exe",
  4.     "https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x64_01.exe",
  5.     "https://dldir1.qq.com/qqfile/qq/TIM3.5.0/TIM3.5.0.22143.exe"
  6. )
  7. # 获取桌面路径
  8. $desktop = [System.Environment]::GetFolderPath('Desktop')
  9. # 创建一个存储作业的数组
  10. $jobs = @()
  11. # 启动并行下载作业
  12. foreach ($url in $urls) {
  13.     $fileName = Split-Path $url -Leaf
  14.     $outputPath = Join-Path $desktop $fileName
  15.     $jobs += Start-Job -ScriptBlock {
  16.         param($downloadUrl, $savePath)
  17.         Invoke-WebRequest -Uri $downloadUrl -OutFile $savePath
  18.     } -ArgumentList $url, $outputPath
  19. }
  20. # 等待所有作业完成
  21. $jobs | ForEach-Object {
  22.     Wait-Job $_
  23.     Remove-Job $_
  24. }
  25. Write-Host "所有文件下载完成!"
复制代码

TOP

往下载对象里订阅添加
DownloadStarted
ChunkDownloadProgressChanged
DownloadProgressChanged
DownloadFileCompleted
这四个事件(参考示例源码,在事件里写进度条代码)

我脑子不好,不会弄进度条这些特效代码,反正那源码用的是ShellProgressBar,你可以试试http://www.nuget.org/packages/ShellProgressBar/

TOP

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

返回列表