【问题标题】:How to set TrustedInstaller as owner of cmd.exe?如何将 TrustedInstaller 设置为 cmd.exe 的所有者?
【发布时间】: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


【解决方案1】:

我找到了解决方案。我的和 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

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 2016-10-25
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多