Stop process logic


I have an installer.exe to install a few programs. When the .exe is finished, it pops up a box and I click on OK (wasn’t possible to do silently).

It has a few programs and the last one it installs is keepass.

I’m wondering if the logic in my script is ok. My concerns are: What if it doesn’t install keepass lastly, what if the file path changes according to operating system?

I would basically like to kill the process once everything is installed.

Perhaps there’s a much easier way to do this and I’m not seeing it?

Thanks for any help.


Start-Process -FilePath 'D:\Chrome_KeePass_Notepad_Skype.exe'

Start-Sleep -s 120

$txtfilepath = "C:\Program Files (x86)\KeePass Password Safe 2\KeePass.exe"

$testpath = test-path $txtfilepath

if ($testpath -eq $true){

Start-Sleep -s 10

Stop-Process -Name "Ninite"


Is “Ninite” the installer process or some other remenant left behind after the installer is complete. If it is just some ghost process left behind, you can you use logic to determine when the actual installer process quits. Regardless, you can use a while loop to continually check for either a process to exist or not exist or a file to exist or not exist. Additionally, there is an environmental variable for program files. Here are some code snippets to help explain.

#wait until a file exists (using while loop)
$myfile = ${env:ProgramFiles(x86)} + "\KeePass Password Safe 2\KeePass.exe"
while (-not (Test-Path $myfile)){}
#Do stuff like stop-process

#wait until a process exists (using while loop)
while (-not (Get-Process -Name "Ninite" -ErrorAction Ignore)){}
#Do stuff like stop-process

#wait until a process goes away (using while loop)
while (Get-Process -Name "installerprocess" -ErrorAction Ignore){}
#Do stuff like stop-process

Check this out:

hi Mike,

Sorry for the late reply. That helped me.