使用命令行工具更改 Windows 网络共享权限

使用命令行工具更改 Windows 网络共享权限

完全不下载subinacl.exe就可以吗?

答案1

你看过icacls.exe和吗cacls.exe?(都在System32文件夹中,至少在 Win7 上)

答案2

对于仍然发现此问题的任何人,您可以使用 POWERSHELL:

Grant-SmbShareAccess -Name example -AccountName Administrators -AccessRight Full -Force
Grant-SmbShareAccess -Name example -AccountName Everyone -AccessRight Change -Force

以下是我使用 POWERSHELL 之前的原始回答:

我最近需要对多个家庭共享执行此操作,以限制“完全控制”。虽然您可以在 NTFS 级别执行此操作,但需要时间进行递归应用,需要时间进行逆转,并且 ADUC MMC 等工具会恢复权限。

似乎没有内置的命令行工具来管理现有共享的权限,仅在初始设置期间,但您可以进行多次授予,因此如果共享暂时脱机不是问题,您可以使用:

NET SHARE example /DELETE /Y
NET SHARE example=C:\FolderPath /GRANT:Everyone,Change /GRANT:Administrators,Full /UNLIMITED

但这对我来说不是一个选择,所以最终使用了优秀的“SetACL.exe”工具,它还有一个针对共享名称的选项。

SetACL.exe -on "example" -ot shr -actn ace -ace "n:S-1-1-0;p:change"
SetACL.exe -on "example" -ot shr -actn ace -ace "n:S-1-5-32-544;p:full"

请注意,这还显示了对每个人(S-1-1-0)和本地管理员(S-1-5-32-544)使用“众所周知的SID”来避免查找,但名称也有效。

为了提高效率,可以将多个更改合并为一个命令:

SetACL.exe -on "example" -ot shr -actn ace -ace "n:S-1-1-0;p:change" -ace "n:S-1-5-32-544;p:full"

请注意,SetACL 命令针对的是共享名称,而不是共享的文件夹路径,后者通常用于 NTFS 权限。

答案3

也许,在 Windows 2003 上。我还没有尝试过......

net share /grant 

从 Win 7 x64 机器编辑评论后。

注意[/GRANT:user,[READ | CHANGE | FULL]]

C:\Users\gbn>net share /?
The syntax of this command is:

NET SHARE
sharename
          sharename=drive:path [/GRANT:user,[READ | CHANGE | FULL]]
                               [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | BranchCach
e | None]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | BranchCache | None]
          {sharename | devicename | drive:path} /DELETE
          sharename \\computername /DELETE


C:\Users\gbn>

相关内容