@建议操作server服务器文件夹时可以映射网络驱动盘

import win32security
import ntsecuritycon as con

FILENAME = r'D:\tmp\acc_test'  #文件夹路径

sd = win32security.GetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION)
dacl = sd.GetSecurityDescriptorDacl()

ace_count = dacl.GetAceCount() #显示具有文件夹权限用户(组)数量
print('Ace count:', ace_count)

for i in range(0, ace_count):
rev, access, usersid = dacl.GetAce(i)
user, group, type = win32security.LookupAccountSid('', usersid)
print('User: {}/{}'.format(group, user), rev, access)
User: user (0, 0) 1179817 #只有该文件夹,查看权限
User: admin (0, 0) 1245631 #只有该文件夹,修改权限
User: administrator (0, 3) 2032127 #此文件夹,子文件夹 全部权限

#删除文件夹权限
Now you are able to read old ACEs and deleting old ones is quite simple:
for i in range(0, ace_count):
dacl.DeleteAce(0)

#掉用add增加权限
And after that you can just add privileges by calling AddAccessAllowedAceEx() [MSDN]:
userx, domain, type = win32security.LookupAccountName ("", "your.user")
usery, domain, type = win32security.LookupAccountName ("", "other.user")

dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 3, 2032127, userx) # 完全控制 @中间3代表权限会被后面文件夹继承 0:不会
dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 3, 1179785, usery) # 只读权限

sd.SetSecurityDescriptorDacl(1, dacl, 0) #可能没有必要
win32security.SetFileSecurity(FILENAME, win32security.DACL_SECURITY_INFORMATION, sd)
I've taken numbers 3, 2032127 and 1179785 from the listing in first half of the script (before running the script I've set up privileges in Explorer->Right Click->Properties->Security->Advanced):
#

#
#例子
# try:
# permit = '1179817'
# acegroup = 'Users'
# folder = 'Z:\\50.测试文件夹\\01.2'
# sd = win32security.GetFileSecurity(folder, win32security.DACL_SECURITY_INFORMATION)
# dacl = sd.GetSecurityDescriptorDacl()
# user1, domain, type = win32security.LookupAccountName('', acegroup)
#
# permisson = int(permit)
# dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 0, permisson, user1) #中间的0 表示只有该文件夹 3表示此文件夹,子文件
# sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary
# win32security.SetFileSecurity(folder, win32security.DACL_SECURITY_INFORMATION, sd)
# except Exception as e:
# print(e)

#python 的os模块操控文件夹
#import os
#import shutil

# try:
# os.mkdir(r'Z:\50.测试文件夹\01.2') #新建文件夹
# except Exception as e:
# print(e)

# try:
# os.rename(r'Z:\50.测试文件夹\01.2',r'Z:\50.测试文件夹\01.3') #重命名文件夹
# except Exception as e:
# print(e)

# try:
# shutil.rmtree(r'Z:/50.测试文件夹/01.3') ##删除名文件夹
# except Exception as e:
# print(e)
PS.调用cmd操控文件夹
http://jingyan.baidu.com/article/d3b74d64c853081f77e60929.html 下载安装pywin32
#创建文件夹
def createfolder(request):
folder=r'Z:/50.测试文件夹/01.3'
result={}
try:
#用wmi连接到远程服务器
pythoncom.CoInitialize()
conn = wmi.WMI(computer=‘192.168.0.1’, user='user', password='user')
cmd_callbat=r"cmd.exe /c mkdir %s" % folder
conn.Win32_Process.Create(CommandLine=cmd_callbat) #执行bat文件
result['isSuccess']=True
result['message']=' 添加成功'
except Exception as e:
print(e)
result['isSuccess'] = False
result['message'] = ' 添加失败'+e
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(json.dumps(result))
return response

来源http://jingyan.baidu.com/article/f3ad7d0ffe8b1409c2345b43.html
http://www.programcreek.com/python/index/478/win32security

最新文章

  1. 【原创】AC自动机小结
  2. ios基础篇(二十四)—— 文字、图片的绘制及其自定义Button
  3. Java面向对象基础知识汇总
  4. 关于KB905474正版验证补丁破解办法 KB905474是个微软操作系统正版/盗版监测间谍软件。更新安装后,右下角有个提示说“系统监测到你的操作系统是盗版”。 如果没有安装的: 在系统提示更新的时候注意看一下,如果包含有“更新KB905474”就去掉“更新KB905474”方框前的勾,点击关闭(注意如果没有去掉那个勾得话,会找不到“关闭”,而是“确定”),在不在提示我该消息前打勾。 如果已经安装
  5. 微软Team Foundation Service 的Scrum模板中的Feature和Backlog Items 的区别【转载】
  6. PAT1078 Hashing
  7. Dorado7 4版本升级5版本问题汇总
  8. php大力力 [016节] 兄弟连高洛峰php教程(2014年 14章数据库章节列表)
  9. 手机APP与原生APP设计的区别
  10. Android 签名(6)编译时源码的签名
  11. 作怪的Buffer
  12. Vue组件选项props
  13. [模板] tarjan/联通分量/dfs树
  14. 【原创】Bug管理操作规范个人经验总结
  15. JAVA自学笔记26
  16. 关于SQL Server将一列的多行内容拼接成一行,合并显示在另外表中
  17. hdu3613 Best Reward manacher+贪心+前缀和
  18. 导致线程死锁容易忽略的一点 SendMessage
  19. Netty原理剖析
  20. [文章存档]Kudu 的 Debug Console 窗口如何查看更多文件

热门文章

  1. JS的replace()的应用
  2. INSTALL_PARSE_FAILED_MANIFEST_MALFORMED 错误
  3. 突然想写点东西,关于web新人的。采用问答方式
  4. JS 改变input 输入框样式
  5. Ext.ComponentQuery.query()
  6. sql - Invalid object name 'dbo.in$'
  7. Data Types
  8. 使用Intellij IDEA构建spark开发环境
  9. 素数判定 AC 杭电
  10. Memcached源码分析——process_command函数解析