0

我目前必须更改 cmd.exe 上所有本地用户的权限。到目前为止,我已经获得了文件的所有权并以我需要的方式更改了权限。

我的问题是,我不知道如何将所有权归还给 TrustedIntstaller。

您可以在下面看到我到目前为止编写的代码。它更改了权限并且没有抛出任何错误,但是在脚本运行之后,所有者仍然设置为 System.

我正在使用 Powershell App Deployment Toolkit,并且脚本以系统用户身份执行。

任何帮助表示赞赏。如果还有其他(更好的)方法可以更改 Windows 文件夹中的权限,请也告诉我。

        $acl_old = get-acl "$envSystem32Directory\cmd.exe"
        $owner_old = $acl_old.Owner

        Execute-Process -Path "takeown.exe" -Parameters "/f C:\windows\system32\cmd.exe"
        Execute-Process -Path "icacls.exe" -Parameters "$envSystem32Directory\cmd.exe /grant:r *S-1-2-0:(RX)"

        $new_permission = get-acl "$envSystem32Directory\cmd.exe"
        $new_owner_object = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList "$owner_old"
        $new_permission.SetOwner($new_owner_object)
        set-acl -Path $envSystem32Directory\cmd.exe -AclObject $new_permissions
4

1 回答 1

0

我找到了解决方案。我的和 boxdogs 代码正在工作。但它并不完整。为了能够恢复 TrustedInstaller 作为所有者,必须加载一些 DLL 和权限。

如果其他人遇到这个问题,这里有一个解决方案。将 DLL-Load 和 Privileges 添加到我的脚本后,它正在工作。

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/87679d43-04d5-4894-b35b-f37a6f5558cb/solved-how-to-take-ownership-and-change-permissions-for-blocked- powershell 中的文件和文件夹

于 2019-04-29T08:41:03.913 回答