I'm using Python to launch AWCC.exe (Alienware Command Center) and the problem I'm having is when close AWCC it doesn't close. It gets removed from the desktop and stays running as a background process. What I need to find out is if AWCC is running foreground or background. I found this on stackoverflow.com but it is for linux and the most I've found on displaying processes is with tasklist that displays all processes including background processes. What it doesn't do is show me what process is foreground or background.
This produces two windows if AWCC.exe is loaded on a different virtual desktop or is running in the background and one of them has zero child processes.
def GetAWCCHandle():
def EnumWindowProc(hwnd, windows):
if win32gui.GetWindowText(hwnd) == 'Alienware Command Center' and win32gui.IsWindowVisible(hwnd):
windows.append(hwnd)
def HasChildren(hwnd):
def EnumWindowProc(hwnd, children):
children.append(hwnd)
children = []
win32gui.EnumChildWindows(hwnd, EnumWindowProc, children)
return bool(len(children))
windows = []
win32gui.EnumWindows(EnumWindowProc, windows)
for hwnd in windows:
print(HasChildren(hwnd))
print(win32gui.GetWindowText(hwnd))
print(win32api.MonitorFromWindow(hwnd))
print(win32gui.GetWindowRect(hwnd))
print(win32process.GetWindowThreadProcessId(hwnd))
print(hwnd)
print()
So far I haven't found any real way to find out if AWCC.exe is running in the foreground or background, but I have found that ...
process = [process for process in psutil.process_iter() if process.name() == 'AWCC.exe'][0]
print(process.num_threads())
print(process.memory_percent())
both double when AWCC.exe is in the foreground.
Does anyone have a solution for compiling a list of background processes?