如何将TrustedInstaller设置为cmd.exe的所有者?

时间:2019-04-26 09:50:45

标签: powershell permissions owner system32 icacls

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

我的问题是,我无法弄清楚如何将所有权返还给TrustedIntstaller。

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

Iam使用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

1 个答案:

答案 0 :(得分: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-files-and-folders-in-powershell