【发布时间】:2019-04-26 09:50:45
【问题描述】:
我目前必须更改 cmd.exe 上所有本地用户的权限。 到目前为止,我已经获得了文件的所有权并以我需要的方式更改了权限。
我的问题是,我不知道如何将所有权归还给 TrustedIntstaller。
您可以在下面看到到目前为止我编写的代码。它更改了权限并且没有抛出任何错误,但是在脚本运行之后,所有者仍然设置为 System.
我正在使用 Powershell 应用程序部署工具包,并且脚本以系统用户身份执行。
感谢任何帮助。如果还有其他(更好的)方法可以更改 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
【问题讨论】:
-
我忘记了 code-sn-p 中的那一行。但它已经在我的脚本中,它不会改变任何东西。 Set-acl -Path "C:\windows\system32\cmd.exe -AclObject $new_permissions
-
查看我之前的回答:Is there ... powershell, that will assign ownership of a file ...?。在您的情况下,将我示例中的帐户名称更改为“NT Service\Trustedinstaller”。请注意,您可能需要运行提升才能使其正常工作。
标签: powershell permissions owner system32 icacls