PowerShell mit mehreren Checkboxen?
Wenn ich die zweite CheckBox anhake wird der Befehl nicht ausgeführt bei der ersten wird er aber ausgeführt. Wie muss ich vorgehen dass beide CheckBoxen funktionieren.
Mein Script sieht so aus
function Test{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# Set the size of your form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 435
$Form.height = 200
$Form.Text = ”Test”
# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font("Times New Roman",12)
$Form.Font = $Font
function Ausführen{
#Paint Ausführen
if($paintCheckBox.checked -eq $true) {mspaint.exe}
#NotePad Ausführen
if($DownloadsCheckBox.checked -eq $true) {Nodepad.exe}
}
#Add an Ausführen button
$AusführenButton = new-object System.Windows.Forms.Button
$AusführenButton.Location = new-object System.Drawing.Size(30,30)
$AusführenButton.Size = new-object System.Drawing.Size(100,40)
$AusführenButton.Text = "Ausführen"
$AusführenButton.Add_Click({(Ausführen)})
$form.Controls.Add($AusführenButton)
#Add a Exit button
$ExitButton = new-object System.Windows.Forms.Button
$ExitButton.Location = new-object System.Drawing.Size(160,30)
$ExitButton.Size = new-object System.Drawing.Size(100,40)
$ExitButton.Text = "Exit"
$ExitButton.Add_Click({$Form.Close()})
$form.Controls.Add($ExitButton)
#Add a CheckBox
$paintCheckBox=New-Object System.Windows.Forms.CheckBox
$paintCheckBox.Name="Paint"
$paintCheckBox.Text="Paint"
$paintCheckBox.TabIndex=0
$paintCheckBox.Location=New-Object System.Drawing.Point(30,80)
$paintCheckBox.Size = new-object System.Drawing.Size(200,40)
$NotePadCheckBox=New-Object System.Windows.Forms.CheckBox
$NotePadCheckBox.Name="NotePad"
$NotePadCheckBox.Text="NotePad"
$NotePadCheckBox.TabIndex=0
$NotePadCheckBox.Location=New-Object System.Drawing.Point(30,110)
$NotePadCheckBox.Size = new-object System.Drawing.Size(200,40)
$paintCheckBox,$NotePadCheckBox | foreach {$Form.Controls.Add($_)}
# Activate the form
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
}
#Call the function
Test