Need help with script (Search for program, if not running, run it) So I run a bat file to run a exe file

Sometimes it fails, when it does, I have a powershell script to close it

So, what I'm looking for, is for script to search for the exe every 30 seconds, or whatever duration I choose. If its not found, I want it to load the bat file.

Any help will be sincerely appreciated.

here is the current script I have



"while($true)
{
    Sleep 2
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate('btg')
    sleep 1
    $wshell.SendKeys('s')

    $promptStringStart = (Get-Date -Format MM/dd/yy` hh:mm:ss) +  "  --  "
    Write-Host $promptStringStart -NoNewline -ForegroundColor Yellow
    Write-Host $promptStringEnd -NoNewline -ForegroundColor Yellow
}"