set file permission on windows

Discussion in 'Python' started by Tim Arnold, Apr 8, 2008.

  1. Tim Arnold

    Tim Arnold Guest

    hi, I need to set file permissions on some directory trees in windows using
    Python.

    When I click on properties for a file and select the 'Security' tab, I see a
    list of known 'Group or user names' with permissions for each entry such as
    Full Control, Modify, Read&Execute, etc.

    I need to (for example) periodically set Group Permissions for one group to
    Read, and another Group to None. I need to apply the settings to several
    directory trees recursively.

    If this was on Unix, I'd just use os.stat I guess. I don't think that will
    work in this case since all I know is the Group names and the permissions I
    need to allow.

    thanks for any pointers,
    --Tim Arnold
    Tim Arnold, Apr 8, 2008
    #1
    1. Advertising

  2. On Apr 8, 12:03 pm, "Tim Arnold" <> wrote:
    > hi, I need to set file permissions on some directory trees in windows using
    > Python.
    >
    > When I click on properties for a file and select the 'Security' tab, I see a
    > list of known 'Group or user names' with permissions for each entry such as
    > Full Control, Modify, Read&Execute, etc.
    >
    > I need to (for example) periodically set Group Permissions for one group to
    > Read, and another Group to None. I need to apply the settings to several
    > directory trees recursively.
    >
    > If this was on Unix, I'd just use os.stat I guess. I don't think that will
    > work in this case since all I know is the Group names and the permissions I
    > need to allow.
    >
    > thanks for any pointers,
    > --Tim Arnold


    According to the following thread, you can use os.chmod on Windows:

    http://mail.python.org/pipermail/python-list/2003-June/210268.html

    You can also do it with the PyWin32 package. Tim Golden talks about
    one way to do it here:

    http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

    Also see the following thread:

    http://mail.python.org/pipermail/python-win32/2004-July/002102.html

    or

    http://bytes.com/forum/thread560518.html

    Hope that helps!

    Mike
    Mike Driscoll, Apr 8, 2008
    #2
    1. Advertising

  3. Tim Arnold

    Tim Arnold Guest

    "Mike Driscoll" <> wrote in message
    news:...
    > On Apr 8, 12:03 pm, "Tim Arnold" <> wrote:
    >> <snip>


    > According to the following thread, you can use os.chmod on Windows:
    >
    > http://mail.python.org/pipermail/python-list/2003-June/210268.html
    >
    > You can also do it with the PyWin32 package. Tim Golden talks about
    > one way to do it here:
    >
    > http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
    >
    > Also see the following thread:
    >
    > http://mail.python.org/pipermail/python-win32/2004-July/002102.html
    >
    > or
    >
    > http://bytes.com/forum/thread560518.html
    >
    > Hope that helps!
    >
    > Mike


    Hi Mike,
    It does help indeed, especially the last two links. That certainly gets me
    started in the right direction. I'm always amazed at the helpful generosity
    of the folks on this list.
    thanks again for the help.
    --Tim Arnold
    Tim Arnold, Apr 8, 2008
    #3
  4. On Apr 8, 1:19 pm, "Tim Arnold" <> wrote:
    > "Mike Driscoll" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > On Apr 8, 12:03 pm, "Tim Arnold" <> wrote:
    > >> <snip>

    > > According to the following thread, you can use os.chmod on Windows:

    >
    > >http://mail.python.org/pipermail/python-list/2003-June/210268.html

    >
    > > You can also do it with the PyWin32 package. Tim Golden talks about
    > > one way to do it here:

    >
    > >http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

    >
    > > Also see the following thread:

    >
    > >http://mail.python.org/pipermail/python-win32/2004-July/002102.html

    >
    > > or

    >
    > >http://bytes.com/forum/thread560518.html

    >
    > > Hope that helps!

    >
    > > Mike

    >
    > Hi Mike,
    > It does help indeed, especially the last two links. That certainly gets me
    > started in the right direction. I'm always amazed at the helpful generosity
    > of the folks on this list.
    > thanks again for the help.
    > --Tim Arnold


    Hi Tim,

    I thought I'd used the methods in those last two links before, but I
    was thinking of changing permissions on running services to reboot a
    PC, which is not quite the same. If you run into more issues, there's
    a PyWin32 mailing list with helpful people there too. You can find it
    here: http://mail.python.org/mailman/listinfo/python-win32

    Mike
    Mike Driscoll, Apr 8, 2008
    #4
  5. Tim Arnold

    Tim Golden Guest

    Tim Arnold wrote:
    > "Mike Driscoll" <> wrote in message
    > news:...
    >> On Apr 8, 12:03 pm, "Tim Arnold" <> wrote:
    >>> <snip>

    >
    >> According to the following thread, you can use os.chmod on Windows:
    >>
    >> http://mail.python.org/pipermail/python-list/2003-June/210268.html
    >>
    >> You can also do it with the PyWin32 package. Tim Golden talks about
    >> one way to do it here:
    >>
    >> http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
    >>
    >> Also see the following thread:
    >>
    >> http://mail.python.org/pipermail/python-win32/2004-July/002102.html
    >>
    >> or
    >>
    >> http://bytes.com/forum/thread560518.html
    >>
    >> Hope that helps!
    >>
    >> Mike

    >
    > Hi Mike,
    > It does help indeed, especially the last two links.


    Hi, Tim. For the purposes of improving that page of mine linked
    above, would you mind highlighting what made it less useful
    than the last two links? On the surface, it seems to match your
    use case pretty closely. Was there too much information? Too
    little? Poor formatting? Just didn't feel right? I've a small set
    of security-related pages in train and I'd rather produce something
    which people find useful.

    Thanks

    TJG
    Tim Golden, Apr 8, 2008
    #5
  6. En Tue, 08 Apr 2008 14:03:06 -0300, Tim Arnold <>
    escribió:

    > hi, I need to set file permissions on some directory trees in windows
    > using
    > Python.


    The hard way: Use the function SetFileSecurity, the pywin32 package
    exposes it. See the Microsoft documentation at
    http://msdn2.microsoft.com/en-us/library/aa374860(VS.85).aspx

    The easy way: the cacls command

    --
    Gabriel Genellina
    Gabriel Genellina, Apr 9, 2008
    #6
  7. Tim Arnold

    Tim Arnold Guest

    "Tim Golden" <> wrote in message
    news:...
    > Tim Arnold wrote:
    >> "Mike Driscoll" <> wrote in message
    >> news:...
    >>> On Apr 8, 12:03 pm, "Tim Arnold" <> wrote:
    >>>> <snip>

    >>
    >>> According to the following thread, you can use os.chmod on Windows:
    >>>
    >>> http://mail.python.org/pipermail/python-list/2003-June/210268.html
    >>>
    >>> You can also do it with the PyWin32 package. Tim Golden talks about
    >>> one way to do it here:
    >>>
    >>> http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
    >>>
    >>> Also see the following thread:
    >>>
    >>> http://mail.python.org/pipermail/python-win32/2004-July/002102.html
    >>>
    >>> or
    >>>
    >>> http://bytes.com/forum/thread560518.html
    >>>
    >>> Hope that helps!
    >>>
    >>> Mike

    >>
    >> Hi Mike,
    >> It does help indeed, especially the last two links.

    >
    > Hi, Tim. For the purposes of improving that page of mine linked
    > above, would you mind highlighting what made it less useful
    > than the last two links? On the surface, it seems to match your
    > use case pretty closely. Was there too much information? Too
    > little? Poor formatting? Just didn't feel right? I've a small set
    > of security-related pages in train and I'd rather produce something which
    > people find useful.
    >
    > Thanks
    >
    > TJG


    Hi TJG. Thanks for the site. Unfortunately, I mis-typed in the previous
    reply and that should have been the 'first two links' instead of 'last two
    links'. In fact I bookmarked your site so I can re-read the material and I
    copied the code to play around with. Excellent example--it contains just
    what I needed to know, esp. since it replaces the dacl instead of modifying
    one. Now I can remove access for 'Everybody' by simply not including it in
    the new dacl.

    thanks!
    --Tim Arnold
    Tim Arnold, Apr 9, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JRV
    Replies:
    2
    Views:
    411
  2. Replies:
    4
    Views:
    5,859
  3. santosh

    Changing file permission in windows

    santosh, May 8, 2006, in forum: C Programming
    Replies:
    4
    Views:
    463
    SM Ryan
    May 9, 2006
  4. Replies:
    1
    Views:
    145
    Anthony Jones
    Jul 27, 2007
  5. Tim McDaniel
    Replies:
    11
    Views:
    319
    Thrill5
    Jan 23, 2009
Loading...

Share This Page