Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell script form that launches a batch file

$
0
0

I have a script that creates a simple Windows form.  One of the things that the form does is launch a batch file.  However, I want the form to close right away and the script to end as soon as the batch file starts.  But it does not.  If I launch "notepad.exe" it works as expected (or any other EXE for that matter).  But if I tell it to launch a batch file instead, the form stays open.  Is there a way to make the form close right away.  I found a post about using Start-Job, but this never launches the batch file.

This works...
$objConfigureButton.Add_Click({$objConfigureButton.Enabled = $false;. Notepad.exe;$objForm.Close()})

This works but leaves the form open...
$objConfigureButton.Add_Click({$objConfigureButton.Enabled = $false;. C:\Scripts\Sysprep.bat;$objForm.Close()})

This never runs the bat file, but does close the form....
$objConfigureButton.Add_Click({$objConfigureButton.Enabled = $false;Start-Job -ScriptBlock {C:\Scripts\Sysprep.bat} -Name Sysprep;$objForm.Close()})

and I have tried this too...
$objConfigureButton.Add_Click({$objConfigureButton.Enabled = $false;Start-Job -ScriptBlock {. C:\Scripts\Sysprep.bat} -Name Sysprep;$objForm.Close()})

Thanks,

NK


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>