0

I tried to open a new incognito chrome window and want to close it.

$URL = 'www.google.com'
$appInstance = Start-Process -FilePath Chrome -passthru -ArgumentList @( '-incognito', $URL, '--new-window')
Write-Host "App ID : " $appInstance.Id
Stop-Process -ID 3716 -Force

Output

App ID :  3716

Error

Stop-Process : Cannot find a process with the process identifier 3716.

My requirement is if I run the script 5 times then 5 chrome instances are open. Now it should close a specific window depending upon its Process ID.

Can it be possible to do?

rAJ
  • 1,295
  • 5
  • 31
  • 66
  • Does this answer your question? [PowerShell - get process ID of called application](https://stackoverflow.com/questions/4762982/powershell-get-process-id-of-called-application) – Cid Jun 15 '20 at 07:43
  • updated question. Can you help? – rAJ Jun 15 '20 at 08:27
  • `taskkill` would be better for this imo. Try `taskkill /f /t /pid 3716` – Nico Nekoru Jun 15 '20 at 17:57
  • I don't think it will work. Reason being the process id i am getting after start the process is not present in the task manager. – rAJ Jun 15 '20 at 18:27
  • Chrome runs multiple child instances -- `'--new-window'` could mean your pid simply appends an existing processs, then ends immediately because it's done -- which is why that pid isn't found. if "taks manager" doesn't show a pid, `processexplorer` by `sysinternals` will. sort using `tree view` -- whatever you're goal is, it might be a lot easier to implement using a an existing session addon – ninMonkey Jun 16 '20 at 09:47
  • So you mean there is no way to do it? I have to kill the complete chrome process. – rAJ Jun 16 '20 at 09:59
  • You might be able to enumerate processes, searching for a window title -- but what is your goal, why do you want to kill one window only? Why not just hit `x` on a window to close it? Then the rest are still open. This sounds like an XY question. – ninMonkey Jun 16 '20 at 10:16

0 Answers0