1

I have a pretty neat mess of batch/python scripts that install a program called MATRIS, followed by about 15 exe updates. Around 11 of these updates open a window telling me the that the update was successful.


Now it would be really fun to run a batch or powershell script which closes all of these windows for me. The last thing I tried was Get-Process | Where-Object {$_.Path -like "MatrisInstaller.APCIPLUS"} | Stop-Process -WhatIf I wasn't sure if it was the name as read in task manager, or like the title of the window, but I tried both. Capture of the window and task manager

Please note that a couple of these are (32 bit) - I'm not sure if that would impact the script.

I was able to run tasklist followed by kill {PID} but PIDs change: I'm not sure how to script it.

Please reply if you need any clarification, I've historically been poor at wording my questions.

2
  • And what is your problem or error message? Commented May 31, 2018 at 5:41
  • No error message, I just can't find a way to close these windows. Nothing I try works or returns an error. Commented May 31, 2018 at 6:47

2 Answers 2

3

In your example, Path is pointing to the executable file on disk, so while possible to use (if it is consistent), it won't match the name you find in the processes tab of Task Manager. Typically, people will use the name as shown on the Details tab of Task manager. For example, with Outlook on my system, these three possibilities are:

Path: C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE
Processes tab: Microsoft Outlook
Details tab: outlook.exe

So, you need a command like this:

Get-Process | Where Name -eq 'Outlook' | Stop-Process

or, better:

Get-Process -Name 'Outlook' | Stop-Process

Note that PowerShell expects you to remove the '.exe' you see in Task manager.

EDIT: Additional technique

If you know the names of the processes, then you can simplify your script by doing something like this:

$processList = "Process1","Process2","Process3" # Add all process names to the list

$processList |
    ForEach-Object {
        Get-Process -Name $_ | Stop-Process
    }
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome, this worked! Each update is a different .exe file, so I'll just make a 15 line .ps1 that has Get-Process -Name 'updateXX' | Stop-Process with each file name. Thank you for your assistance!
@WilliamBachynsky, I updated my answer with some additional information that might help simplify your script.
You bloody legend, that works a charm. I did get an error or two when I ran it, due to me having closed a couple already, but on the next install i should have all of them open, so no errors. Love your work!
0

You were almost there, just need to change "Path" to "ProcessName" like so:

Get-Process | Where-Object {$_.ProcessName -like "MatrisInstaller.APCIPLUS"} | Stop-Process -WhatIf

3 Comments

This did not work, no errors or anything, all the tasks remain listed, and windows open. Any further suggestions?
The tasks wont close with the -whatif parameter remove that and see.
Nope, still no good. To clarify, the whole line now looks like: Get-Process | Where-Object {$_.ProcessName -like "MatrisInstaller.APCIPLUS"} | Stop-Process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.