如何使用Windows命令行授予用户对目录的权限(读、写、修改)?
当前回答
attrib +r +a +s +h <folder name> <file name> to hide
attrib -r -a -s -h <folder name> <file name> to unhide
其他回答
在Vista中,不支持使用cacls。以下是前几条帮助热线:
C:\>cacls
NOTE: Cacls is now deprecated, please use Icacls.
Displays or modifies access control lists (ACLs) of files
你应该使用icacls。这是你授予John对D:\test文件夹及其所有子文件夹的完全控制权的方式:
C:\>icacls "D:\test" /grant John:(OI)(CI)F /T
根据MS文档:
F =完全控制 CI =容器继承——该标志表示从属容器将继承此ACE。 OI = Object Inherit -该标志表示从属文件将继承ACE。 /T =递归应用到现有文件和子文件夹。(OI和CI只适用于新文件和子文件夹)。图片来源:@AlexSpence。
要获得完整的文档,您可以不带参数地运行“icacls”,或者在这里和这里查看Microsoft文档
这对我来说很管用:
手动打开被拒绝访问的文件夹。 在该文件夹中选择可执行/应用程序文件。 右键点击属性->兼容性 现在查看特权级别,并检查它是否为以管理员身份运行 为所有用户单击Change Settings。
现在问题解决了。
优秀点 卡林·达里
我有很多脚本使用调用,我把它们移动到icacls 我怎么也找不到一个脚本来改变根挂载卷的例子:d:\datafolder。我最终创建了下面的脚本,它将卷作为临时驱动器挂载,然后应用,然后卸载它。这是我发现可以更新根挂载安全性的唯一方法。
1获取文件夹挂载GUID到临时文件,然后读取GUID将卷挂载为临时驱动器X:应用sec并记录更改,然后仅从X:驱动器卸载卷,这样挂载的文件夹除了应用sec之外不会被更改或中断。
以下是我的脚本示例:
**mountvol "d:\%1" /L >tempDrive.temp && FOR /f "tokens=*" %%I IN (tempDrive.temp) DO mountvol X: %%I
D:\tools\security\icacls.exe %~2 /grant domain\group:(OI)(CI)F /T /C >>%~1LUNsec-%TDWEEK%-%TMONTH%-%TDAY%-%TYEAR%-%THOUR%-%TMINUTE%-%TAM%.txt
if exist x:\*.* mountvol X: /d**
attrib +r +a +s +h <folder name> <file name> to hide
attrib -r -a -s -h <folder name> <file name> to unhide
损坏权限:重新获得对文件夹及其子对象的访问权
虽然这个问题的大部分答案都有一定的价值,但恕我直言,没有一个答案是完整的。下面(可能)是Windows 7的一个完美的解决方案,如果你被损坏的权限设置锁定的文件夹:
icacls "c:\folder" /remove:d /grant:r Everyone:(OI)(CI)F /T
对于Windows 10,用户/SID必须在/remove:d选项后指定:
icacls "c:\folder" /remove:d Everyone /grant:r Everyone:(OI)(CI)F /T
. 注:
The command is applied to the specified directory. Specifying the user "Everyone" sets the widest possible permission, as it includes every possible user. The option "/remove:d" deletes any explicit DENY settings that may exist, as those override explicit ALLOW settings: a necessary preliminary to creating a new ALLOW setting. This is only a precaution, as there is often no DENY setting present, but better safe than sorry. The option "/grant" creates a new ALLOW setting, an explicit permission that replaces (":r") any and all explicit ALLOW settings that may exist. The "F" parameter (i.e. the permission created) makes this a grant of FULL control. The "/T" parameter adds recursion, applying these changes to all current sub-objects in the specified directory (i.e. files and subfolders), as well as the folder itself. The "(OI)" and "(CI)" parameters also add recursion, applying these changes to sub-objects created subsequently. .
附录(2019/02/10)-
上面的Windows 10命令行是今天好心推荐给我的,所以就在这里。我还没有Windows 10来测试它,但是如果你有的话请尝试一下(然后请在下面发表评论)。
第一步更改只涉及删除DENY设置。可能没有任何DENY设置,所以该选项可能没有区别。我的理解是,在Windows 7上,你不需要在/remove:d后指定用户,但我可能错了!
.
附录(2019/11/21)-
用户astark建议将Everyone替换为术语*S-1-1-0,以便命令独立于语言。我只有英文版的Windows安装,所以我不能测试这个建议,但它似乎是合理的。
推荐文章
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 为什么git在Windows下记不住我的密码
- Git克隆/拉不断冻结在“存储密钥在缓存?”
- 有没有替换Windows (Visual C)的unistd.h ?
- 从Windows批处理文件设置系统环境变量?
- 在Sublime Text 2中使用Ctrl+D进行多个选择时,我如何跳过匹配?
- #定义WIN32_LEAN_AND_MEAN具体排除了什么?
- 如何添加一个设置路径只执行批处理文件?
- 最好的轻量级web服务器(只有静态内容)的Windows
- npm犯错!错误:EPERM:操作不允许,重命名
- 崇高的文本从命令行
- 如何保持Python脚本输出窗口打开?
- 使用.bat文件检查文件夹是否存在
- 如何查看Windows库(*.lib)的内容
- 在Windows中删除大文件夹最快的方法是什么?