PFZheng / psutil

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

AccessDenied errors for most operations not owned by my user #280

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
This code generates AccessDenied exceptions for all operations (except getting 
the PID) on processes not owned by my user in W7 64bits, python 2.7.3 64bits, 
psutil 0.4.1 64bits, even if i have admin rights and the python process is 
elevated.

import psutil
import logging

logging.basicConfig()
log = logging.getLogger(__name__)

for p in psutil.process_iter():
    if p.pid == 0:
        continue
    process_attributes = list()
    for attribute in ['username', 'pid', 'nice', 'exe']:
        try:
            process_attributes.append(getattr(p, attribute))
        except (psutil.AccessDenied) as err:
            log.error('{}: Trying to access {} of {}'.format(err.__class__.__name__,
                                                             attribute, err))
    print process_attributes

Output is something like this:
ERROR:__main__:AccessDenied: Trying to access username of (pid=1636)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=1636)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=1636)
[1636]
ERROR:__main__:AccessDenied: Trying to access username of (pid=2556)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=2556)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=2556)
[2556]
ERROR:__main__:AccessDenied: Trying to access username of (pid=1548)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=1548)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=1548)
[1548]
['MYUSER', 4264, 32, 'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe']
ERROR:__main__:AccessDenied: Trying to access username of (pid=3260)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=3260)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=3260)
[3260]
ERROR:__main__:AccessDenied: Trying to access username of (pid=4752)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=4752)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=4752)
[4752]
['MYUSER', 5020, 32, 'C:\\Program Files (x86)\\Mozilla 
Thunderbird\\thunderbird.exe']
['MYUSER', 4796, 32, 'C:\\Program Files (x86)\\GNU\\GnuPG\\gpg-agent.exe']
ERROR:__main__:AccessDenied: Trying to access username of (pid=328)
ERROR:__main__:AccessDenied: Trying to access nice of (pid=328)
ERROR:__main__:AccessDenied: Trying to access exe of (pid=328)
[328]
['MYUSER', 4436, 32, 'C:\\Program Files (x86)\\Mozilla 
Thunderbird\\plugin-container.exe']
['MYUSER', 4492, 32, 'C:\\Python27\\Scripts\\ipython.exe']
ERROR:__main__:AccessDenied: Trying to access exe of (pid=5948)
['MYUSER', 5948, 32]
['MYUSER', 5176, 32, 'C:\\Python27\\python.exe']
['MYUSER', 4676, 128, 'C:\\Program Files\\Process Hacker 2\\ProcessHacker.exe']
['MYUSER', 5100, 32, 'C:\\Windows\\system32\\cmd.exe']
ERROR:__main__:AccessDenied: Trying to access exe of (pid=5660)
['MYUSER', 5660, 32]
['MYUSER', 5696, 32, 'C:\\Python27\\python.exe']
['MYUSER', 2852, 32, 'C:\\Python27\\python.exe']

I got curious what process 5660 was...
'\??\C:\Windows\system32\conhost.exe 
"-819514783406431421117177328-3794250371789057852-943298914-27174460378563238 '
That's the commandline ProcessHacker got.

What is the expected output?
Information about each process in the system, like ProcessHacker do when i 
elevate it.

What do you see instead?
No information except PID, like ProcessHacker would do when it isn't elevated.

What version of psutil are you using? What Python version?
python 2.7.3 64bits, psutil 0.4.1 64bits

On what operating system? Is it 32bit or 64bit version?
W7 64bits

Original issue reported on code.google.com by kurzedme...@gmail.com on 11 Jun 2012 at 8:46

GoogleCodeExporter commented 9 years ago
Yes, I'm aware of this and I don't know any workaround.
AFAIK, process hacker is able to determine those information because it is 
installed as a driver or something like that, something which shouldn't be 
easily suitable for a Python module.

Original comment by g.rodola on 12 Jun 2012 at 3:59

GoogleCodeExporter commented 9 years ago
Closing out as won't fix.

Original comment by g.rodola on 21 Jun 2012 at 4:35