我目前必须更改 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