kiranvizru / psutil

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

psutil.username is occur AccessDenied error #389

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I write some simple code about netstat-like.
I want to display network connection info and pid, process name, process 
username, cwd, exe and more..
But psutil.username, psutil,getcwd(), psutil.exe is occur errors.

C:\test>test.py
TCP     192.168.126.10:139      0.0.0.0:0       LISTEN  4       System  NT 
AUTHORITY\SYSTEM
TCP     0.0.0.0:445     0.0.0.0:0       LISTEN  4       System  NT 
AUTHORITY\SYSTEM
TCP     0.0.0.0:80      0.0.0.0:0       LISTEN  4       System  NT 
AUTHORITY\SYSTEM
UDP     192.168.126.10:138      0.0.0.0:0               4       System  NT 
AUTHORITY\SYSTEM
UDP     192.168.126.10:137      0.0.0.0:0               4       System  NT 
AUTHORITY\SYSTEM
UDP     0.0.0.0:445     0.0.0.0:0               4       System  NT 
AUTHORITY\SYSTEM
TCP     0.0.0.0:1025    0.0.0.0:0       LISTEN  428     lsass.exe       NT 
AUTHORITY\SYSTEM
UDP     0.0.0.0:500     0.0.0.0:0               428     lsass.exe       NT 
AUTHORITY\SYSTEM
UDP     0.0.0.0:4500    0.0.0.0:0               428     lsass.exe       NT 
AUTHORITY\SYSTEM
Traceback (most recent call last):
  File "C:\test\test.py", line 99, in <module>
    main()
  File "C:\test\test.py", line 25, in main
    test()
  File "C:\test\test.py", line 51, in test
    print conn_type + "\t" + local + "\t" + remote + "\t" + status + "\t" + str(process.pid) + "\t" + process.name + "\t
" + process.username
  File "C:\Python27\lib\site-packages\psutil\__init__.py", line 371, in username
    return self._platform_impl.get_process_username()
  File "C:\Python27\lib\site-packages\psutil\_psmswindows.py", line 174, in wrapper
    raise AccessDenied(self.pid, self._process_name)
psutil._error.AccessDenied: (pid=696, name='svchost.exe')

Maybe this error is my code has no priviliges to access svchost.exe.
Anyone know how to fix this error or why occur this error?

regard

Original issue reported on code.google.com by deman...@gmail.com on 5 Jun 2013 at 6:42

GoogleCodeExporter commented 9 years ago
There's nothing you can do about that except maybe running the Python process 
as NT AUTHORITY SYSTEM user.
In general it is natural to expect AccessDenied exceptions when querying 
processes owned by another user, especially for lower PIDs.

Original comment by g.rodola on 5 Jun 2013 at 9:29