设置文件夹权限的Windows使用Python在

编程入门 行业动态 更新时间:2024-10-24 04:32:38
本文介绍了设置文件夹权限的Windows使用Python在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用Python创建了一个用户AD帐户何时创建一个新的个人文件夹。正在创建的文件夹,但权限是不正确的。可以的Python将用户添加到新创建的文件夹,并改变他们的权限?我不知道从哪里开始编码这一点。

I'm using Python to create a new personal folder when a users AD account is created. The folder is being created but the permissions are not correct. Can Python add the user to the newly created folder and change their permissions? I'm not sure where to begin coding this.

推荐答案

您想要的 win32security 模块,这是对的pywin32 。这里是做你想要做的事情有些例子。

You want the win32security module, which is a part of pywin32. Here's an example of doing the sort of thing you want to do.

这个例子的文件创建一个新的DACL,并取代旧的,但很容易修改现有之一;所有你需要做的就是从安全描述符中的现有DACL而不是建立空单,像这样:

The example creates a new DACL for the file and replaces the old one, but it's easy to modify the existing one; all you need to do is get the existing DACL from the security descriptor instead of creating an empty one, like so:

import win32security import ntsecuritycon as con FILENAME = "whatever" userx, domain, type = win32security.LookupAccountName ("", "User X") usery, domain, type = win32security.LookupAccountName ("", "User Y") sd = win32security.GetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION) dacl = sd.GetSecurityDescriptorDacl() # instead of dacl = win32security.ACL() dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_GENERIC_READ | con.FILE_GENERIC_WRITE, userx) dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_ALL_ACCESS, usery) sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary win32security.SetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION, sd)

更多推荐

设置文件夹权限的Windows使用Python在

本文发布于:2023-11-12 11:50:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   权限   Python   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!