dvarrazzo / py-setproctitle

A Python module to customize the process title
Other
497 stars 65 forks source link

Provide an interface to read the titles of the running processes on Windows #40

Open dvarrazzo opened 14 years ago

dvarrazzo commented 14 years ago

Originally submitted by daniele.varrazzo as issue 6:

I only know it can be done (see Process Explorer [1]), but how, I don't know.

Also, I wouldn't know if it should be a graphical interface (displaying processes in a tree, allowing to send them signal etc.) or a command line tool. I suppose the first would be more useful from a windows user PoV but more complex to write and with fat dependencies.

Contributions are welcome.

[1] http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

dvarrazzo commented 14 years ago

Comment by daniele.varrazzo:

Sysinternals' "handle" program [1] returns the value as well

C:\dev\setproctitle\build\lib.win32-2.6>c:\Python26\python.exe Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import setproctitle setproctitle.setproctitle("Hello, world!") import os os.getpid() 804

C:\dev>x:\Sistema\sysinternals\handle.exe -p 804 -a

Handle v3.11 Copyright (C) 1997-2005 Mark Russinovich Sysinternals - www.sysinternals.com

18: File C:\dev\setproctitle\build\lib.win32-2.6 39C: Event \BaseNamedObjects\python(804): Hello, world! 3A4: Directory \BaseNamedObjects 3A8: Event [...]

but the source file (that must be no more than a couple of syscalls) is not available anymore [2].

[1] http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx [2] http://technet.microsoft.com/en-us/sysinternals/bb847944.aspx

ysc3839 commented 1 month ago

You could try modify the buffer returned by GetCommandLineA and GetCommandLineW. Doing so can't change process name, but can change process command line. And it's visible in Task Manager and Process Explorer.