【问题标题】:How to capture DISM output and reflect the status with progress bar using Powershell?如何使用 Powershell 捕获 DISM 输出并通过进度条反映状态?
【发布时间】:2019-09-27 16:40:38
【问题描述】:

我想用这个方法拍一张图片

DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

参考:

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/deploy-windows-using-full-flash-update--ffu

在powershell中我是这样用的

& DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

它在捕获时显示命令窗口。 我是否可以在捕获时创建一个类似于进度条的 GUI?

感谢您的建议。

我已经创建了这个 PowerShell 脚本。但是在执行此操作时

$Result = & DISM.exe /capture-ffu /imagefile=E:\TEST\capture.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0

进度条没有开始或显示进度,它只是显示为空(白条)。 请任何建议。

Add-Type -assembly System.Windows.Forms

## -- Create The Progress-Bar
$ObjForm = New-Object System.Windows.Forms.Form
$ObjForm.Text = "Image Capturing"
$ObjForm.WindowState = 'Maximized'
$ObjForm.BackColor = "White"

$ObjForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ObjForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen

## -- Create The Label
$ObjLabel = New-Object System.Windows.Forms.Label
$ObjLabel.Text = "Starting. Please wait ... "
$ObjLabel.Left = 5
$ObjLabel.Top = 10
$ObjLabel.Width = 500 - 20
$ObjLabel.Height = 15
$ObjLabel.Font = "Tahoma"
## -- Add the label to the Form
$ObjForm.Controls.Add($ObjLabel)

$PB = New-Object System.Windows.Forms.ProgressBar
$PB.Name = "PowerShellProgressBar"
$PB.Value = 0
$PB.Style="Continuous"

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 700 - 40
$System_Drawing_Size.Height = 20
$PB.Size = $System_Drawing_Size
$PB.Left = 5
$PB.Top = 40
$ObjForm.Controls.Add($PB)

## -- Show the Progress-Bar and Start The PowerShell Script
$ObjForm.Show() | Out-Null
$ObjForm.Focus() | Out-NUll
$ObjLabel.Text = "Starting. Please wait ... "
$ObjForm.Refresh()

Start-Sleep -Seconds 1

$Result = & DISM.exe /capture-ffu /imagefile=E:\TEST\capture.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0
$Counter = 0
ForEach ($Item In $Result) {
    ## -- Calculate The Percentage Completed
    $Counter++
    [Int]$Percentage = ($Counter/$Result.Count)*100
    $PB.Value = $Percentage
    $ObjLabel.Text = "Capturing The Image"
    $ObjForm.Refresh()
    Start-Sleep -Milliseconds 150
    # -- $Item.Name
    "`t" + $Item.Path

}

$ObjForm.Close()
Write-Host "`n"

更新

我认为 DISM.exe 完成后无法报告。 我必须让进度条一直滚动,直到这个过程完成。

& DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

谁能给我点意见。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    Write-Progress 够你用吗?

    .....
    ForEach ($Item In $Result) {
        $Counter++
        [Int]$Percentage = ($Counter/$Result.Count)*100
        Write-Progress -activity "Completion" -status "Status" -PercentComplete $Percentage   
    }
    

    【讨论】:

    • 嗨@Tatu,我试过了,但我的解决方案也一样,进度条没有分层,它只是在捕获时显示白条。我的意思是在执行这个$Result = & DISM.exe /capture-ffu /imagefile=E:\TEST\capture.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0
    • 所以您的问题更多的是关于捕获 DISM 的输出。您需要在后台启动它并捕获输出。例如,请参阅social.technet.microsoft.com/Forums/en-US/…
    • 这没有帮助。重点是展示 DISM 到目前为止所取得的进展……但在 DISM 完成之前,控制权不会返回。
    猜你喜欢
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2023-03-12
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多