使用 Powershell GUI 的实时数据
Real Time Data With Powershell GUI
我在这里挣扎。
使用 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 和 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()