简体   繁体   中英

creating permissions on shared windows folder with python

I'm using this code in python 3.3 with the pywin32 library to share a folder. How can I now add pemissions to the folder? The following code sets no permissions to the shared folder. I want to add a specific user as read/write

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)

you should try and use win32security module. This site shows an example of using it to set user permissions

An alternative to the win32security module is to wimp out and use the cacls program, which is rather easier to use, see at http://support.microsoft.com/kb/162786/en-us for example :

from subprocess import *

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

proc.wait()

print "Child exited with",proc.returncode

The echo y is because this stupid program asks an "are you sure?" question. On windows 7, cacls is deprecated (but still works), use icacls instead (or xcalcs from the resource kit).

Of course creating child processes to do this will not be as efficient as calling the Win32 API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM