我在python 3.3中使用这段代码与pywin32库共享一个文件夹。
我现在如何向文件夹中添加权限?以下代码不设置对共享文件夹的权限。我要将特定用户添加为读/写

import win32net
import win32netcon

shinfo={}

shinfo['netname']='python test'
shinfo['type']=win32netcon.STYPE_DISKTREE
shinfo['remark']='data files'
shinfo['permissions']=0
shinfo['max_uses']=-1
shinfo['current_uses']=0
shinfo['path']='C:\\sharedfolder'
shinfo['passwd']=''
server='192.168.1.100'

win32net.NetShareAdd(server,2,shinfo)

最佳答案

win32security模块的另一种选择是退出并使用更易于使用的cacls程序,参见http://support.microsoft.com/kb/162786/en-us例如:

from subprocess import *

proc = Popen("echo y|cacls filename /E /G BUILTIN\\Users:R", shell=True)

proc.wait()

print "Child exited with",proc.returncode

因为这个愚蠢的程序会问“你确定吗?”问题。在windows 7上,cacls已被弃用(但仍然有效),请改用echo y(或资源工具包中的icacls)。
当然,创建子进程来执行此操作的效率不如调用win32 api。

10-04 17:08