Reading the access attributes of directories in Windows

Tim Golden mail at timgolden.me.uk
Sat Aug 21 09:10:50 EDT 2010


On 21/08/2010 1:01 PM, vsoler wrote:
> Personally, I am impressed of the power of python, your winsys
> library, and overall, how easy it is to customize the scripting of
> one's day to day needs.

Glad you find it useful...


>
> I have started testing your first script
>
> from winsys import fs, security
> root = fs.dir ("c:/")
> for d in root.dirs (ignore_access_errors=True):
>     print (d, "=>", d.security ())
>
> Howwvwer, I am getting an error:
>
>>>> ================================ RESTART ================================
>>>>
> c:\$recycle.bin\ =>  O:BAD:PAI(A;;FA;;;BA)(A;OICIIO;GA;;;BA)(A;;FA;;;SY)
> (A;OICIIO;GA;;;SY)(A;;0x1201ad;;;BU)
> c:\aeat\ =>  O:BAD:AI(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)
> (A;OICIIOID;GA;;;SY)(A;OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)
> (A;OICIIOID;SDGXGWGR;;;AU)
> c:\archivos de programa\ =>  O:SYD:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)
> (A;;FA;;;SY)(A;;FA;;;BA)
> c:\documents and settings\ =>  O:SYD:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)
> (A;;FA;;;SY)(A;;FA;;;BA)
> c:\hp\ =>  O:SYD:AI(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)
> (A;OICIIOID;GA;;;SY)(A;OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)
> (A;OICIIOID;SDGXGWGR;;;AU)
> Traceback (most recent call last):
>    File "C:/Users/Vicente/Documents/VS/Python/test6.py", line 5, in
> <module>
>      print(d, "=>",d.security())
>    File "C:\Python31\lib\site-packages\winsys\fs.py", line 1044, in
> security
>      return security.security (self, options=options)
>    File "C:\Python31\lib\site-packages\winsys\security.py", line 585,
> in security
>      return Security.from_object (str (obj), obj_type, options=options)
>    File "C:\Python31\lib\site-packages\winsys\security.py", line 475,
> in from_object
>      sd = wrapped (win32security.GetNamedSecurityInfo, obj,
> object_type, options)
>    File "C:\Python31\lib\site-packages\winsys\exc.py", line 55, in
> _wrapped
>      raise exception (errno, errctx, errmsg)
> winsys.security.x_security: (5, 'GetNamedSecurityInfo', 'Acceso
> denegado.')
>>>>
>
> I am using a system in the Spanish language. As you can see in the
> last line, 'Acceso denegado' or 'Access denied' even though the flag
> "ignore_access_errors" is set to True.
>
> I am using python 3.1 on Windows 7. What do you think is the origin of
> this problem?
>
> Vicente Soler

Can you run Python from within a Run-As-Administrator command
prompt? Windows Vista & 7 bring a lot more security to the basic
Windows model. If you can't do that, it might be possible to
elevate your privileges enough to read the security attributes
using the security.change_privileges function.

TJG



More information about the Python-list mailing list