0

I'm writing a python script to get the running process and their "application name" (e.g. chrome.exe -> Google Chrome). I've no problem to find process name (chrome.exe), but how can I find the application name?

I've already written a database (columns are: processName appName category), but there is another way to get these info using only python? (I would like to use this script on Windows-Linux-MacOS).

Any idea?

cybronele
  • 31
  • 5
  • There are no "applications" on Linux (and probably on MacOS, either). Only processes. – DYZ Oct 08 '20 at 06:53
  • yeah I know, that's why I used an example. I would like to get for any process, the name we see (another example: if the process is "soffice.bin", I see LibreOffice. And I want to get the name I see) – cybronele Oct 08 '20 at 06:57
  • That's the window name. [This may help](https://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id) – DYZ Oct 08 '20 at 07:14
  • Task Manager uses the file description from the PE image, which you can query via `win32api.GetFileVersionInfo`. – Eryk Sun Oct 08 '20 at 07:24
  • For example, to list the file description in all available translations: `exe = r'C:\Program Files\Google\Chrome\Application\chrome.exe';` `blk_trans = r'\VarFileInfo\Translation';` `blk_descr = r'\StringFileInfo\{:04x}{:04x}\FileDescription';` `trans = win32api.GetFileVersionInfo(exe, blk_trans);` `for t in trans: win32api.GetFileVersionInfo(exe, blk_descr.format(*t))`. – Eryk Sun Oct 08 '20 at 07:31
  • @ErykSun yeah but it works only in Windows I think, I need something for Linux and MacOS as well – cybronele Oct 08 '20 at 07:35
  • @DYZ yes but it's C++... Do you know any alternatives in Python? – cybronele Oct 08 '20 at 07:37
  • Determining the user-facing representation of a process' name is inherently platform-specific. Unless there is a Python module that wraps the platform-specific implementation behind a platform-agnostic interface you will be writing platform-specific code. – IInspectable Oct 08 '20 at 09:00
  • In Windows you could also go a step further to look for a UWP app name. For macOS, maybe look for a plist for an application bundle. For Linux, maybe support Snap apps (snaps), but otherwise I think mapping a binary to an application package will be expensive and dependent on the distro. – Eryk Sun Oct 08 '20 at 09:12
  • @IInspectable I guessed, what about a kind of database I talked before? Processes name are similar for operative systems... Using a fuzzy library I can get similar processes and then I can give them the name I want, is it less expensive? – cybronele Oct 08 '20 at 09:26
  • @ErykSun thanks for answering me with details for each os. Can you give me an opinion as well about my previous answer above? – cybronele Oct 08 '20 at 09:28
  • How does a database fare in face of applications you do not know? That includes the unbounded set of applications that have not yet been released. – IInspectable Oct 08 '20 at 09:49
  • I suppose to know every program is running. If i don't know it, probably is system's. If it has just been installed, I create a kind of module to save this app with a name and a category choosen by me – cybronele Oct 08 '20 at 10:06

0 Answers0