所以我创建了一个带按钮的窗口,但是我希望在窗口中嵌入一些shell来实现某些功能,而不是打开一个新窗口。
例如,脚本的不同部分会提示用户输入目标,然后对该计算机执行命令。我希望从shell中的这个表单中做到这一切
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Dan's Security Tool"
$Icon = New-Object system.drawing.icon
("c:\users\sadmiller2\documents\icon.ico")
$Form.Icon = $Icon
$Image =
[system.drawing.image]::FromFile("c:\users\sadmiller2\pictures\defender.jpg")
$Form.BackgroundImage = $Image
$Form.BackgroundImageLayout = "None"
# None, Tile, Center, Stretch, Zoom
$Form.Width = $Image.Width
$Form.Height = $Image.Height
$Font = New-Object System.Drawing.Font("Times New Roman",20,
[System.Drawing.FontStyle]::Regular)
# Font styles are: Regular, Bold, Italic, Underline, Strikeout
$Form.Font = $Font
$form.StartPosition = "CenterScreen"
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Dan's Security Tool"
$Label.BackColor = "Transparent"
$Label.ForeColor = "White"
$Label.AutoSize = $True
$Label.Location = New-Object System.Drawing.Point(485,25)
$ContinueButton = New-Object System.Windows.Forms.Button
$ContinueButton.Location = New-Object System.Drawing.Point(530,590)
$ContinueButton.Size = New-Object System.Drawing.Size(130,30)
$ContinueButton.Text = "Continue"
$ContinueButton.Add_MouseHover({$ContinueButton.backcolor = [System.Drawing.Color]::DarkGray})
$ContinueButton.Add_MouseLeave({$ContinueButton.backcolor = [System.Drawing.Color]::White})
$ContinueButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $ContinueButton
$form.Controls.Add($ContinueButton)
$Form.Controls.Add($Label)
$Form.ShowDialog()
答案 0 :(得分:0)
您可能希望在文本框中启用“多行”属性或类似内容。
假设文本框的句柄为$textbox1
,并且您要将数据存储在$output
变量中,请显示输出
$textbox1.Text = $output