本帖最后由 fish猫 于 2025-8-8 09:57 编辑
保存成ps1文件之后在powershell执行就可以避免在msStore中下载了
ps1代码
# 设置下载参数
$url = "https://windbg.download.prss.microsoft.com/dbazure/prod/1-2402-24001-0/windbg.msixbundle"
$outputFile = "$PSScriptRoot\windbg.msixbundle"
# 配置SSL协议(解决可能的证书问题)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# 创建WebClient对象
$webClient = New-Object System.Net.WebClient
# 初始化进度跟踪参数
$global:totalBytes = 0
$global:receivedBytes = 0
$global:lastUpdate = [DateTime]::Now
$global:lastBytes = 0
# 注册进度变更事件
Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -Action {
$global:totalBytes = $EventArgs.TotalBytesToReceive
$global:receivedBytes = $EventArgs.BytesReceived
}
# 创建计时器更新进度条
$timer = New-Object Timers.Timer
$timer.Interval = 1000 # 1秒更新一次
# 定义计时器触发动作
$timerAction = {
if ($global:totalBytes -gt 0) {
# 计算下载速度
$timeDiff = [DateTime]::Now - $global:lastUpdate
$bytesDiff = $global:receivedBytes - $global:lastBytes
$speed = ($bytesDiff / $timeDiff.TotalSeconds).ToString("0.00") + " KB/s"
# 更新进度条
$progress = ($global:receivedBytes / $global:totalBytes) * 100
Write-Progress -Activity "正在下载 WinDbg..." `
-Status ("已下载: {0} MB / {1} MB | 速度: {2}" -f `
($global:receivedBytes/1MB).ToString("0.00"),
($global:totalBytes/1MB).ToString("0.00"),
$speed) `
-PercentComplete $progress
# 更新速度计算基准
$global:lastUpdate = [DateTime]::Now
$global:lastBytes = $global:receivedBytes
}
}
# 启动计时器
$timerElapsed = Register-ObjectEvent -InputObject $timer -EventName Elapsed -Action $timerAction
$timer.Start()
try {
# 开始异步下载
$webClient.DownloadFileAsync([Uri]$url, $outputFile)
# 等待下载完成
while ($webClient.IsBusy) {
Start-Sleep -Milliseconds 500
}
# 停止计时器
$timer.Stop()
Unregister-Event -SourceIdentifier $timerElapsed.Name
Write-Progress -Completed -Activity "下载完成"
# 安装MSIX包
if (Test-Path $outputFile) {
Add-AppxPackage -Path $outputFile -ErrorAction Stop
Write-Host "✅ WinDbg 安装成功" -ForegroundColor Green
}
else {
Write-Host "❌ 文件下载失败,请检查网络连接" -ForegroundColor Red
}
}
catch {
Write-Host "❌ 发生错误: $_" -ForegroundColor Red
}
finally {
$webClient.Dispose()
Get-EventSubscriber | Unregister-Event
Get-Job | Remove-Job -Force
}
有兄弟问,怎么下载最新版本的windbg
1.打开msdn的网址,https://learn.microsoft.com/zh-cn/windows-hardware/drivers/debugger/
2.下载文件之后用记事本打开,复制里面的Url,替换上面ps1脚本的链接,就能下载最新的windbg了
|