使用 python 创建共享 Windows 文件夹的权限 [英] creating permissions on shared windows folder with python

查看:113
本文介绍了使用 python 创建共享 Windows 文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有 pywin32 库的 python 3.3 中使用此代码来共享文件夹.我现在如何将 pemissions 添加到文件夹中?以下代码不设置共享文件夹的权限.我想将特定用户添加为读/写

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)

推荐答案

win32security 模块的替代方案是退出并使用 cacls 程序,这是相当更易于使用,请参见 http://support.microsoft.com/kb/162786/en-us 例如:

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

echo y 是因为这个愚蠢的程序会问你确定吗?"题.在 Windows 7 上,cacls 已弃用(但仍然有效),请改用 icacls(或资源包中的 xcalcs).

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).

当然,创建子进程来执行此操作的效率不如调用 Win32 API.

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

这篇关于使用 python 创建共享 Windows 文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆