2017-09-26 29 views
0

所以我創建了一個帶有按鈕的窗口,但我想在窗口中爲某些函數嵌套一個shell,而不是打開一個新窗口。在表格中使用Powershell

例如,腳本的不同部分提示用戶輸入目標,然後對該計算機執行命令。我想要做所有這些,從這種形式的殼

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() 
+1

輸出可以包含一些代碼,你有什麼到目前爲止已經試過?請參閱[這裏](https://stackoverflow.com/help/how-to-ask)瞭解如何提出最有可能得到有效回答的問題。 – pucky124

+0

您還可以看看Sapien powerShell Studio,Admin Script Editor和Visual Studio 2017.它們都提供了使用PowerShell的GUI構建。 –

回答

0

你會想在文本框中啓用'多行'屬性或類似的東西。

假設文本框的手柄是$textbox1,你有數據顯示存儲在一個$output變量,顯示像

$textbox1.Text = $output 
+0

我可以對輸入框進行反轉,並仍然使用它來運行類似於讀取主機的命令嗎? $ target = $ textbox2.txt – Daniel

+0

是的,這是正確的。 '$ Target = $ textbox2.text' –