Hello Guys,
PS newbie here. In the below code i am trying to assign the 4 list options a value (computername), so that i can select an option (which holds a value of the computername assigned) to use for the command at the bottom.
Although i don’t know how to actually make the list options hold any value, anyone lend a hand?
Thanks.
Load VB Text Window Framework and Prompt for Hostname###
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
$Computer =
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = “Select a Computer”
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = “CenterScreen”
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($.KeyCode -eq “Enter”)
{$x=$objListBox.SelectedItem;$objForm.Close()}})
$objForm.Add_KeyDown({if ($.KeyCode -eq “Escape”)
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = “OK”
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = “Cancel”
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = “Please select a computer:”
$objForm.Controls.Add($objLabel)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Height = 80
[void] $objListBox.Items.Add(“Shannon”)
[void] $objListBox.Items.Add(“Dale”)
[void] $objListBox.Items.Add(“Ryan”)
[void] $objListBox.Items.Add(“Daniel”)
$objForm.Controls.Add($objListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$x
###Enter message to send to Host and transmit
$Message = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter Message”, “Message to send”, “$env:String”)
Invoke-WmiMethod -Class Win32_Process -ComputerName $Computer -Name Create -ArgumentList “C:\Windows\System32\msg.exe * $Message”