[python-win32] Re: Changing Windows NT File Permissions

Justin Johnson justinjohnson at gmail.com
Mon Jul 19 19:41:04 CEST 2004

Does the following code look right for getting permissions on an
existing file and then adding users to the permissions list?  It seems
to be working for me on some files, but on another it completed
successfully and then when I tried to view permissions on the file
using the windows explorer I got a popup that said:

The permissions on file.ini are incorrectly ordered, which may cause
some entries to be ineffective.  Press OK to continue and sort the
permissions correctly, or Cancel to reset the permissions.

Should I be using something other than
DACL_SECURITY_INFORMATION for the info passed to GetFileSecurity?

def giveUsersFullControlOfFile(userIds, file):
   info = win32security.DACL_SECURITY_INFORMATION
   sd = win32security.GetFileSecurity(file, info)
   acl = sd.GetSecurityDescriptorDacl()

   for userId in userIds:
       sidUser = win32security.LookupAccountName(None,userId)[0]
       sidCreator = pywintypes.SID()
       sidCreator.SetSubAuthority(0, ntsecuritycon.SECURITY_CREATOR_OWNER_RID)
       acl.AddAccessAllowedAce(win32file.FILE_ALL_ACCESS, sidUser)
       acl.AddAccessAllowedAce(win32file.FILE_ALL_ACCESS, sidCreator)

   sd.SetSecurityDescriptorDacl(1, acl, 0)
   win32security.SetFileSecurity(file, info, sd)

----- Original Message -----
From: Roger Upole <rwupole at msn.com>
Date: Fri, 16 Jul 2004 18:56:58 -0400
Subject: [python-win32] Re: Changing Windows NT File Permissions
To: python-win32 at python.org

The value you need is 

Other possible values are 

bitwise or combination of any of them)

It threw an error when you passed it 1 
because 1 is OWNER_SECURITY_INFORMATION, and you

passed it a security descriptor without an owner 
set.  And 0 doesn't specify that *any* info should be 



More information about the Python-win32 mailing list