gpt4 book ai didi

powershell - 使用 Powershell GUI 的实时数据

转载 作者:行者123 更新时间:2023-12-02 23:59:41 24 4
gpt4 key购买 nike

我在这里挣扎。

使用Powershell和GUI,如何自动刷新表单上的数据?

以下脚本示例,如何使用我的计算机执行的进程数自动更新标签?

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Sample Form"
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Number of process executed on my computer"
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.ShowDialog()

最佳答案

您需要在表单中添加一个计时器来为您进行更新。然后将收集进程计数所需的代码添加到.Add_Tick,如下所示:

function UpdateProcCount($Label)
{
$Label.Text = "Number of processes running on my computer: " + (Get-Process | measure).Count
}

$Form = New-Object System.Windows.Forms.Form
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.Add_Tick({UpdateProcCount $Label})
$timer.Enabled = $True
$Form.Text = "Sample Form"
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Number of process executed on my computer"
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.ShowDialog()

关于powershell - 使用 Powershell GUI 的实时数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com