Tehc
Tehc

Reputation: 689

Executing different .cmd Files inside Powershell Script

Im trying to execute a .cmd file inside of my Powershell Script. How can i implement that?

Each Checkbox (if checked) should execute another .cmd file.

Here's the Powershell Code i got so far. (instead of the command i just checked if the chexboxes are even selected):

#----------------------------------------------
#Checkbox Events
#----------------------------------------------

$handler_button1_Click= 
{
$listBox1.Items.Clear();    
if ($checkBox1.Checked)    {  $listBox1.Items.Add( "Checkbox 1 is checked"  ) }
if ($checkBox2.Checked)    {  $listBox1.Items.Add( "Checkbox 2 is checked"  ) }
if ($checkBox3.Checked)    {  $listBox1.Items.Add( "Checkbox 3 is checked"  ) }
if ($checkBox4.Checked)    {  $listBox1.Items.Add( "Checkbox 4 is checked"  ) }
if ($checkBox5.Checked)    {  $listBox1.Items.Add( "Checkbox 5 is checked"  ) }
if ($checkBox6.Checked)    {  $listBox1.Items.Add( "Checkbox 6 is checked"  ) }

if ( !$checkBox1.Checked -and !$checkBox2.Checked -and !$checkBox3.Checked -and !$checkBox4.Checked -and !$checkBox5.Checked -and !$checkBox6.Checked) {   $listBox1.Items.Add("No CheckBox selected....")} 
}

Upvotes: 0

Views: 63

Answers (1)

Chris Dent
Chris Dent

Reputation: 4250

Call it the cmd file:

& C:\Path\To\cmd.cmd

Since you only fill listBox1 when you have a checked box, you can significantly simplify the last test.

if ($listBox1.Items.Count -eq 0) {
    $listBox1.Items.Add("No CheckBox selected....")
}

Upvotes: 1

Related Questions