Using python, I need to be able to detect when a windows explorer window has been closed by the user. At first I tried PID's before i realised that it was all connected to a central proccess, "explorer.exe" :( classic noobish me (this meant that PID wasn't changed at all after it was closed). So my question is, how would i be able to detect when a windows explorer windows has been closed. Thank you :)
Here is my current code (it definitely works, but it can't detect when it closes because explorer.exe also runs the task bar etc) :
import psutil
import re
def check4pid(PROCNAME):
for proc in psutil.process_iter():
if proc.name() == PROCNAME:
PIDX=re.search('pid=(.*?), name',str(proc)).group(1)
#print proc
print PIDX
if psutil.pid_exists(int(PIDX)):
print "a process with PID %d exists" % int(PIDX)
else:
print "a process with PID %d does not exist" % int(PIDX)
check4pid("explorer.exe")