чего-то ветка не развивается... вот и решил я подбросить пример реализации [more=примитивного просмотрщика процессов]param ($interval = 10)
#функция построения списка процессов
function Get-ProcessInfo {
$array = New-Object System.Collections.ArrayList
$script:colProc = ps | select Name, Id, CPU, PrivateMemorySize, WorkingSet, Description, Company | sort Name
$array.AddRange($colProc)
$dtgGrid.DataSource = $array
$frmMain.Refresh()
}
#функция автообновления списка процессов
function Set-ProcessAuto {
if ($mnuAuto.Checked -eq $false) {
$mnuAuto.Checked = $true
$tmrTime.Start()
}
else {
$mnuAuto.Checked = $false
$tmrTime.Stop()
}
}
#обработчик события для mnuKill
$OnClick_mnuKill= {
$SelectedRow = $dtgGrid.CurrentRowIndex
if ($colId = $script:colProc[$SelectedRow].Id) {
Stop-Process -id $colId
Start-Sleep -milliseconds 500
Get-ProcessInfo
}
}
#загружаем основную форму
$OnLoad_frmMain= {
Get-ProcessInfo
Set-ProcessAuto
}
#загружаемые сборки
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
#элементы формы
$frmMain = New-Object System.Windows.Forms.Form
$mnuMain = New-Object System.Windows.Forms.MenuStrip
$mnuFile = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuKill = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuSep0 = New-Object System.Windows.Forms.ToolStripSeparator
$mnuExit = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuView = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuRefr = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuAuto = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuHelp = New-Object System.Windows.Forms.ToolStripMenuItem
$mnuAbot = New-Object System.Windows.Forms.ToolStripMenuItem
$dtgGrid = New-Object System.Windows.Forms.DataGrid
$tmrTime = New-Object System.Windows.Forms.Timer
#обобщения
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Point = New-Object System.Drawing.Point
#главное меню
$mnuMain.Items.AddRange(@($mnuFile, $mnuView, $mnuHelp))
#mnuFile
$mnuFile.Text = "&File"
$mnuFile.DropDownItems.AddRange(@($mnuKill, $mnuSep0, $mnuExit))
#mnuKill
$mnuKill.Text = "&Kill"
$mnuKill.Add_Click($OnClick_mnuKill)
#mnuSep0
#mnuExit
$mnuExit.Text = "E&xit"
$mnuExit.Add_Click( { $frmMain.Close() } )
#mnuView
$mnuView.Text = "&View"
$mnuView.DropDownItems.AddRange(@($mnuRefr, $mnuAuto))
#mnuRefr
$mnuRefr.Text = "&Refresh"
$mnuRefr.Add_Click( { Get-ProcessInfo } )
#mnuAuto
$mnuAuto.Text = "Auto &update"
$mnuAuto.Add_Click( { Set-ProcessAuto } )
#mnuHelp
$mnuHelp.Text = "&Help"
$mnuHelp.DropDownItems.AddRange(@($mnuAbot))
#mnuAbot
$mnuAbot.Text = "&About"
$mnuAbot.Add_Click( { Get-AboutDialog } )
#dtgGrid
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 25
$dtgGrid.Location = $System_Drawing_Point
$System_Drawing_Size.Height = 550
$System_Drawing_Size.Width = 802
$dtgGrid.Size = $System_Drawing_Size
$dtgGrid.CaptionVisible = $false
$dtgGrid.PreferredColumnWidth = 109
$dtgGrid.Add_Click( { Set-ProcessAuto } )
#tmrTime
$tmrTime.Interval = $interval * 100
$tmrTime.Add_Tick( { Get-ProcessInfo } )
#frmMain
$System_Drawing_Size.Height = 597
$System_Drawing_Size.Width = 803
$frmMain.ClientSize = $System_Drawing_Size
$frmMain.Controls.Add($mnuMain)
$frmMain.Controls.Add($dtgGrid)
$frmMain.FormBorderStyle = "FixedSingle"
$frmMain.MaximizeBox = $false
$frmMain.StartPosition = "CenterScreen"
$frmMain.Text = "Process Viewer"
$frmMain.Add_Load($OnLoad_frmMain)
#вывод окна About
function Get-AboutDialog {
$frmAbot = New-Object System.Windows.Forms.Form
$lblAbot = New-Object System.Windows.Forms.Label
$btnClos = New-Object System.Windows.Forms.Button
#lblAbot
$lblAbot.Text = "(C) 2008 - 2011 ComradG special for Ru-Board `n
Process Viewer is a sample that can help you stay knowledgeable
"
$lblAbot.TextAlign = "MiddleCenter"
$System_Drawing_Point.X = 5
$System_Drawing_Point.Y = 29
$lblAbot.Location = $System_Drawing_Point
$System_Drawing_Size.Height = 50
$System_Drawing_Size.Width = 330
$lblAbot.Size = $System_Drawing_Size
#btnClos
$btnClos.Text = "Close"
$System_Drawing_Point.X = 132
$System_Drawing_Point.Y = 97
$btnClos.Location = $System_Drawing_Point
$btnClos.Add_Click( { $frmAbot.Close() } )
#frmAbot
$System_Drawing_Size.Width = 350
$System_Drawing_Size.Height = 137
$frmAbot.ClientSize = $System_Drawing_Size
$frmAbot.Controls.Add($lblAbot)
$frmAbot.Controls.Add($btnClos)
$frmAbot.FormBorderStyle = "FixedSingle"
$frmAbot.MaximizeBox = $false
$frmAbot.MinimizeBox = $false
$frmAbot.ShowInTaskbar = $false
$frmAbot.StartPosition = "CenterScreen"
$frmAbot.Text = "About..."
#показываем само окно
$frmAbot.ShowDialog() | Out-Null
}
#показываем основное окно
$frmMain.ShowDialog() | Out-Null[/more]