Multiple instances of process

I’m trying to install visual studio code by creating psadt package.
In Show installationwelcome
I have to close the app if the user is already running the application with user prompt.


 $proc = Get-process -Name 'code' -ErrorAction - silentlycontinue
Show-InstallationWelcome -Closeapps 'code'  

But only once instance is getting closed how can I close all the instances at once with user interaction.
Please suggest.

I don’t use Show-InstallationWelcome so there may be things I’m missing, but my first thought would be to use a ForEach.

The following will kill all “code” processes. If you replace line 4 with your Show-InstallationWelcome line, it should iterate through all the code processes and prompt to close each one. You may need to pull the window title (or other) in order to clarify to the user which window needs to be closed.

$CodeProcesses = (Get-Process | Where-Object {$_.Name -like "code"}).Id
Foreach ($CodeProcess in $CodeProcesses)
  Stop-Process -Id $CodeProcess -Force

Hi, which version of the toolkit are you using. I have seen this behavior with v3.8.2, in v3.8.4 this seems to be solved.

Show-InstallationWelcome -CloseApps 'code' -Silent

This should kill all instances.

If you MUST have user interaction, first try this:

Show-InstallationWelcome -CloseApps 'code' 
Show-InstallationWelcome -CloseApps 'code' -Silent

The first line will prompt and the second will kill the multiple instances.

Hi, this didn’t work. It’s prompting again and again.