
我有這個腳本文件,目前正在將可執行文件的“經過身份驗證的用戶”權限設置為“ReadAndExecute” - 它在 Windows 10 上運行良好,但需要在 Windows 7 上運行 - 但它不是:
$file = (Resolve-Path 'c:\Dir\file.exe').Path;
$acl = (Get-Item $file).GetAccessControl('Access');
acl.SetAccessRuleProtection($True, $True);
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule('Authenticated Users', 'Write', 'None', 'None', 'Allow');
$acl.RemoveAccessRuleAll($ar);
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule('Authenticated Users', 'Modify', 'None', 'None', 'Allow');
$acl.RemoveAccessRuleAll($ar);
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule('Authenticated Users', 'ReadAndExecute', 'None', 'None', 'Allow');
$acl.SetAccessRule($ar);
Set-ACL -Path $file -AclObject $acl;
這會運行,但它不會設定經過身份驗證的用戶的權限,如果我將呼叫更改GetAccessControl
為沒有參數'Access'
,在 Win7 上我會收到此錯誤:
The security identifier is not allowed to be the owner of this object.
無論如何可以實現我想要做的事情嗎?
額外要求:
- 我無法在電腦上安裝其他應用程序,請將其視為 Win 7 的普通安裝
- 它必須以非互動方式運行 - 因為它是無人值守安裝腳本的一部分