【发布时间】:2017-01-19 06:22:58
【问题描述】:
您好,我是 Powershell 新手。我正在查看 GUI 表单上的 Get-WmiObject -Class Win32_Product 输出。
提前致谢。
以下是代码,我需要为按钮添加标签并为每个按钮分配一个功能。
标签:卸载 功能:卸载 Start-Process Powershell -verb runas # 加载 Windows 窗体程序集 [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void][System.Windows.Forms.Application]::EnableVisualStyles( ) # 创建一个 GUI $form = New-Object System.Windows.Forms.Form $form.Size = New-Object System.Drawing.Size(920,500) $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]:: Fixed3D $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen $dataGridView = New-Object System.Windows.Forms.DataGridView $dataGridView.Size = New-Object System.Drawing.Size(900,400) $button =新对象 System.Windows.Forms.Button $button.Location = 新对象 System.Drawing.Size(400,420) $button.Size = 新对象 System.Drawing.Size(75,25) $button.text = " Uninstall" $form.Controls.Add($button) $form.Controls.Add($dataGridView) # 选择合适的列 $dataGridView.Columns.Insert(0, (New-Object System.Windows.Forms.DataGridViewButtonCell)) $dataGridView .ColumnCount = 8 $dataGr idView.ColumnHeadersVisible = $true $dataGridView.Columns[0].Name = "卸载" $dataGridView.Columns[1].Name = "描述" $dataGridView.Columns[2].Name = "IdentifyingNumber" $dataGridView.Columns[ 3].Name = "名称" $dataGridView.Columns[4].Name = "供应商" $dataGridView.Columns[5].Name = "版本" $dataGridView.Columns[6].Name = "标题" $dataGridView。 Columns[7].Name = "InstallLocation" $dataGridView.Columns[0].width = 40 $dataGridView.Columns[1].width = 200 # 获取项目列表 .Check,$.Description,$.IdentifyingNumber,$.Name,$.Vendor,$.Version,$.Caption,$.InstallLocation) | out-null }#> # 刷新函数 gridClick(){ $rowIndex = $dataGridView.CurrentRow.Index $columnIndex0 = $dataGridView.ColumnIndex+1 $columnIndex1 = $dataGridView.ColumnIndex+2 $columnIndex2 = $dataGridView.ColumnIndex+3 $ columnIndex3 = $dataGridView.ColumnIndex+4 $columnIndex5 = $dataGridView.ColumnIndex+5 #Write-Host $rowIndex #Write-Host $columnIndex0 #Write-Host $dataGridView.Rows[$rowIndex].Cells[0].value Write-主机 $dataGridView.Rows[$rowIndex].Cells[$columnIndex0].value 写入主机 $dataGridView.Rows[$rowIndex].Cells[$columnIndex1].value 写入主机 $dataGridView.Rows[$rowIndex].Cells[ $columnIndex5].value #$IdentifyNumber = $dataGridView.Rows[$rowIndex].Cells[$ClassKey].value #$Name = $dataGridView.Rows[$rowIndex].Cells[$columnIndex0].value #$classKey = ' IdentificationNumber=$IdentifyingNumber.value,Name=$Name.value,Version=$Version.value' #Write-Host $classKey #([wmi]”\$server\root\cimv2:Win32_Product.$classKey”).uninstall( ) } $Uninstall = $dataGridView.Add_CellMouseClick({gridClick} ) # 显示表单 [void]$form.ShowDialog()
【问题讨论】:
-
哪个 Powershell 版本?标记特定版本意味着需要仅在该版本上工作的解决方案。由于 PS2/3/4 完全不同,标记所有这些可能无关紧要。
-
您在寻找什么样的 GUI 表单?
Out-GridView够好吗? -
感谢您的回复.. Out-Gridview 对我来说是公平的,但 Matt Szadziul ans 是我正在寻找的。span>
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0