windows - 语言中立的文件系统访问规则

标签 windows powershell security acl regional-settings

我一直在像这样的脚本中调整 ACL:

     $Acl = get-acl -Path $File
     $rule = New-Object -TypeName system.security.accesscontrol.filesystemaccessrule -ArgumentList ('Authenticated Users','Read','Allow')
     $Acl.setaccessrule($rule)
     set-acl -Path $File -AclObject $Acl

这在我的英语系统上运行良好,但我在荷兰语系统上收到了一份报告:“Kan een aantal of alle id-verwijzingen niet omzetten”位于 setaccessrule($rule)

该错误的翻译(“可能是一个数字或所有 id 引用都无法转换。”)让我觉得该机器上可能不存在英语Authenticated Users,并且我需要一种与语言无关的方式来识别该组。

  1. 内置群组是否特定于语言?
  2. 我怎样才能以与语言无关的方式做同样的事情?

谢谢。

最佳答案

我没有可以使用其他语言进行测试的计算机,但我相信下面的代码应该适合您。

本质上,问题是您在创建 时希望使用 IdentityReference 类型来选择 AuthenticatedUserSid 而不是 String 表示形式>FileSystemAccessRule 对象。 See here for the documentation.

$acl = Get-Acl -Path $File
$si = New-Object -TypeName 'System.Security.Principal.SecurityIdentifier' -ArgumentList @([System.Security.Principal.WellKnownSidType]::AuthenticatedUserSid, $null)
$rule = New-Object -TypeName 'System.Security.AccessControl.FileSystemAccessRule' -ArgumentList @($si, 'Read', 'Allow')
$acl.setaccessrule($rule)
Set-Acl -Path $File -AclObject $acl

关于windows - 语言中立的文件系统访问规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54222763/

相关文章:

windows - 为什么 CreateProcess 给出错误 193(%1 不是有效的 Win32 应用程序)

powershell - 检查 GPU PowerShell

powershell - 在powershell中将参数传递给Set-Alias的正确方法是什么?

javascript - 如何阻止非浏览器客户端提交请求?

c - 在 C 代码中使用 ReadFile

windows - Windows XP 真的有负错误代码吗?

c - 端口正在监听但 "No connection could be made because the target machine actively refused it "

powershell - 如何在 Jenkins 中将 PowerShell 脚本作为作业运行

javascript - 同源策略导致从 www.example.com 到 example.com 的 Ajax 请求被拒绝?

php - 在 PHP 中使用准备好的语句/存储过程时如何保护自己免受 SQL 注入(inject)?