[python-win32] Get executables corresponding to system tray icons?

Tim Roberts timr at probo.com
Mon Sep 19 20:12:00 CEST 2011


reckoner wrote:
> Hi,
>
> Is there a way to use Python to get a list of all the icons in the 
> system tray (lower right hand corner) and their associated processes and 
> executables?
>
> Here is a thread on how to do this using AHK:
>
>     http://www.autohotkey.com/forum/topic17314.html
>
> but it relies heavily on AHK, and the problem with that is that it is 
> difficult to get at the output from AHK scripts (without writing to a 
> file or the clipboard, for example).

Well, it IS possible, but it's a fair amount of Windows magic.  See if
this is enough to get you started in porting the AHK script to Python:

import win32con
import win32gui
import win32process
import ctypes

OpenProcess = ctypes.windll.kernel32.OpenProcess
VirtualAllocEx = ctypes.windll.kernel32.VirtualAllocEx
VirtualFreeEx = ctypes.windll.kernel32.VirtualFreeEx
CloseHandle = ctypes.windll.kernel32.CloseHandle

def TrayIcons():
    hwnd = win32gui.FindWindow( "Shell_TrayWnd", "" )
    print hwnd
    tid, pid = win32process.GetWindowThreadProcessId( hwnd )
    print pid
    hProc = OpenProcess( 0x38, 0, pid )
    print hProc
    pProc = VirtualAllocEx( hProc, 0, 32, 0x1000, 4 )

    print hex(pProc)
    VirtualFreeEx( hProc, pProc, 0, 0x8000 )
    CloseHandle( hProc )

TrayIcons()



-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list