Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

username field empty #846

Closed
quentinhardy opened this issue Jun 24, 2016 · 1 comment
Closed

username field empty #846

quentinhardy opened this issue Jun 24, 2016 · 1 comment

Comments

@quentinhardy
Copy link

Hello,

When I use the following python code as an administrator on windows, some usernames are empty:

>> run pyshell 
>>> import sys
>>> print (sys.version)
2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
>> import psutil
>>> print psutil.__version__
4.1.0
>>> for proc in psutil.process_iter():print proc.as_dict(attrs=['username', 'pid', 'name', 'exe', 'cmdline', 'status'])
[...]
{'username': 'NT AUTHORITY\\SYSTEM', 'status': 'running', 'exe': None, 'name': 'System Idle Process', 'pid': 0, 'cmdline': []}
{'username': 'NT AUTHORITY\\SYSTEM', 'status': 'running', 'exe': None, 'name': 'System', 'pid': 4, 'cmdline': []}
{'username': None, 'status': 'running', 'exe': None, 'name': 'smss.exe', 'pid': 252, 'cmdline': None}
[...]

Notice the username of the smss.exe process (i.e. System) is empty.

If I use the following powershell code as an administrator, I see all usernames:

$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}

ProcessName                                        Id Owner                    
-----------                                        -- -----                    
[...]             
services                                          428 Système                  
smss                                              252 Système                  
spoolsv                                          1244 Système                  
[...]

Why I can't see usernames (e.g SYSTEM) of some processes with psutil.process_iter() while I can with powershell for example?

Thank you in advance for your help,

@giampaolo
Copy link
Owner

So Process.as_dict() method sets None for any "field" it is unable to determine due to permission errors so it is very likely that if you'd use Process.username() method directly you will see the actual AccessDenied exception being raised and unfortunately there's nothing you can do about that.
Power shell is able to do that because it uses the WMI interface, which has no such (permission) limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants