Psutil boosts AccessDenied for all non-user processes when receiving process attributes

I ran into a serious problem: I cannot access information about (most) processes that do not belong to the user. For example, the following:

for proc in psutil.process_iter():
    try:
        print proc.pid, proc.username

    except psutil.AccessDenied:
        print "denied"

prints:

0 NT AUTHORITY\SYSTEM
4 NT AUTHORITY\SYSTEM
428 denied
444 denied
632 my_user
648 denied
676 my_user
704 denied
748 denied
772 denied
804 denied
824 denied
832 denied
880 my_user
920 denied
988 denied
1052 denied
...

For the same “denied” processes, methods such as get_cpu_times () work fine.

UPD: Sorry, I run this thing many times with different attributes and different fingerprints, that I inserted the output from another piece of code (printed username, not name). But I hope the matter is still clear ...

+4
source share
1 answer

, C-. , whay GetProcessImageFileName() QueryFullProcessImageName() ( , , /UNC-), , .

, .

_psutil_mswindows.c ( 502):

if (GetProcessImageFileName(hProcess, &exe, nSize) == 0) {
    CloseHandle(hProcess);
    if (GetLastError() == ERROR_INVALID_PARAMETER) {
        // see https://code.google.com/p/psutil/issues/detail?id=414
        AccessDenied();
    }
    else {
        PyErr_SetFromWindowsErr(0);
    }
    return NULL;
}

EDIT:
, , . Win7 SP1 x64 Python 2 (2.7.6) psutil.Process: exe, get_ionice(), get_memory_maps(), get_nice(), get_cwd()/getcwd(), get_open_files(), name, nice username.

, , - Windows-, , psutil , The Wrong Way ™ ( , Microsoft).

+2

Source: https://habr.com/ru/post/1526913/


All Articles