I have a .bat file that was written long ago by someone else, and there may be a better way to do this, but the .bat file runs a Powershell script, the Powershell script looks for a process running on the machine and on machine start up the Powershell script will kill an existing running process, if running, and then start the .exe file.
However, I am having an issue with the .cmd prompt window staying open and not only that, it stays open above the launched application (WPF app running full screen mode).
The .bat file code is
powershell -file "c:\SomeFolder\scripts\ManageApp2.ps1" -f "c:\SomeFolder\SomeApp.exe" -p "Check_Out" -S
Is there a way to have have the .cmd window close after the .bat file fires? Would it be done in the .bat file? I have see using /min "" but that didn't seem to work (or maybe I did it wrong).
The Powershell file script it runs looks like this:
#####Params#####
param([string]$f = "empty", [string]$p = "empty", [switch]$k, [switch]$S, [switch]$h)
if ($f -eq "empty" -or $p -eq "empty" -or $h) {
Write-Host "ManageApp.ps1 -f <filename> -p <process> -t <start/stop> [-h]"
Write-Host " -f absolute path to app to run"
Write-Host " -p process of app as found in Task Manager"
Write-Host " -k just kill process and do not restart app. Cannot use with -S"
Write-Host " -S Stay Alive. will re-countdown if process every leaves memory.
Cannot use with -k"
Write-Host " -h optional switch. shows this help"
Write-Host " This app will kill the app if found in memory then"
Write-Host " restart it (default) or not (if -k is set)"
Exit
}
#$app='$f'
$appProcess=$p
$sleepCountdown=1 #in seconds
#kill app
$processActive = Get-Process $appProcess -ErrorAction SilentlyContinue
if($processActive)
{
Stop-Process -Force -processname $appProcess
}
if(!$k)
{
if ($S) {
#Start-Job -ScriptBlock {
while ($true) {
Start-Sleep -Seconds 1
$processActive = Get-Process $appProcess -ErrorAction SilentlyContinue
if (!$processActive) {
$sC = $sleepCountdown
while ($sC -gt 0) {
echo "Program will start in $sC seconds..."
Start-Sleep -Milliseconds 1000 #sleep for 1sec to allow flash to let go of file first and wait for windows startup to finish:
$sC--
}
#run app
Start-Process -FilePath $f
}
}
#} | Wait-Job
} else {
while ($sleepCountdown -gt 0) {
echo "Program will start in $sleepCountdown seconds..."
Start-Sleep -Seconds 1 #sleep for 1sec to allow app to let go of file first and wait for windows startup to finish:
$sleepCountdown--
}
#run app
#Invoke-Expression -Command $app
Start-Process -FilePath $f
}
}
Any suggestions on hwo to run this and then have the prompt window close after the launch of the app or it runs?