无法设置文件权限。 Powershell错误:使用参数“ 1”调用“ SetAccessRule”的异常:“某些或所有标识引用无法转换。”在线:9字符:1+ $ acl.SetAccessRule($ accessRule)
> $Path = "c:\WindowsService"
> $acl = Get-Acl $Path
> $UserName = "DESKTOP-12345DT\firstname.lastname"
> $Right = "Read,Write,ReadAndExecute"
> $InheritanceFlag = @([System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.InheritanceFlags]::ObjectInherit)
> $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
> $aclRuleArgs = $UserName,$Right,$InheritanceFlag,$PropagationFlag, "Allow"
> $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($aclRuleArgs)
> $acl.SetAccessRule($accessRule)
> $acl | Set-Acl $Path
>
> New-Service -Name CoreWindowsService -BinaryPathName >c:\WindowsService\CoreWindowsServiceProject.exe -Credential
> DESKTOP-12345DT\firstname.lastname -Description "Core Windows Service
> Processor" -DisplayName "CoreWindowsService" -StartupType Automatic
问题出在用户凭证($ UserName)上。如果使用域名代替计算机名,则可以使用。