How to close an instance of file explorer using python?

0

I have 3 instances of File Explorer running on my system. In the task manager, there is only a single process_id assigned to explorer.exe So if i want to kill one particular instance of explorer window using python, how can I do so? How can I uniquely identify any instance of explorer.exe so that i can use the terminate method in wmi package.

akshit bhatia

Posted 2018-05-14T07:57:12.293

Reputation: 113

I'd assume you have to use python bindings for the win32 api to send a WM_CLOSE message after you identify the correct window via some criterias (windows name, window class), never did it but check out https://stackoverflow.com/questions/22728081/anyway-to-get-a-window-handle-by-its-title-using-win32-api

– T Nierath – 2018-05-14T08:35:24.443

Answers

0

You can use taskkill and the Python os.system():

import os
os.system("taskkill /pid <ProcessID>")

alexfrancow

Posted 2018-05-14T07:57:12.293

Reputation: 26

Hello, When I open several instances of file explorers, there is only a single pid for all the instances in the task manager. So how can I identify the explorer window that I want to open? – akshit bhatia – 2018-05-15T05:37:52.703