kiranvizru / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

(Windows) directly determine process exe instead of guessing it from cmdline #293

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As of right now on Windows we determine the process executable path by guessing 
it from the cmdline:
http://code.google.com/p/psutil/source/browse/tags/release-0.5.0/psutil/_psmswin
dows.py#167
http://code.google.com/p/psutil/source/browse/tags/release-0.5.0/psutil/__init__
.py#224

This is unfortunate because cmdline raises AccessDenied for almost any process 
except the ones owned by the current user.
In r1394 I used GetProcessImageFileName() which fails less often and avoids the 
cmdline guessing.

Example script:

for p in sorted(psutil.process_iter(), key=lambda x: x.pid):
    print p.pid,
    try:
        print p.exe
    except psutil.AccessDenied, err:
        print 'AD'

===============================
Before
===============================

0 AD
4 AD
268 AD
300 AD
356 AD
392 AD
404 AD
432 AD
488 AD
504 AD
512 AD
540 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
556 AD
616 AD
672 AD
700 AD
756 AD
852 AD
856 AD
876 AD
936 AD
1032 AD
1224 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
1268 AD
1280 AD
1452 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
1552 AD
1584 AD
1760 AD
1836 AD
1860 AD
1984 AD
2004 AD
2144 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
2340 C:\Python27\python.exe
2808 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
3012 AD

===============================
Now
===============================

0 AD
4 AD
268 AD
300 AD
356 AD
392 AD
404 AD
432 AD
488 AD
504 AD
512 AD
540 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
556 AD
616 AD
672 AD
700 AD
756 AD
852 C:\Windows\System32\conhost.exe
856 C:\Windows\System32\cmd.exe
876 AD
936 AD
1032 AD
1224 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
1268 C:\Program Files\TortoiseSVN\bin\TSVNCache.exe
1280 AD
1452 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
1456 C:\Windows\System32\dllhost.exe
1468 C:\Python27\python.exe
1552 AD
1584 AD
1760 C:\Windows\System32\taskhost.exe
1836 C:\Windows\System32\dwm.exe
1860 C:\Windows\explorer.exe
1984 C:\Windows\System32\VBoxTray.exe
2004 C:\Program Files\TortoiseHg\TortoiseHgOverlayServer.exe
2144 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
2808 C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe
3012 C:\Users\user\Desktop\procexp64.exe

Original issue reported on code.google.com by g.rodola on 29 Jun 2012 at 3:31

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 29 Jun 2012 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 29 Jun 2012 at 6:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r1394 == revision a8405e698412

Original comment by g.rodola on 2 Mar 2013 at 12:09