这是我尝试过的:
$a = (Get-ItemProperty -Path .\Desktop.ini -Name Attributes).Attributes
Set-itemproperty -Path .\Desktop.ini -Name Attributes -Value ($a -bor [System.IO.FileAttributes]::System)
但属性没有改变(Get-itemproperty -Path .\Desktop.ini -Name Attributes).attributes)
返回“正常”。
[System.IO.File]::SetAttributes(string path, System.IO.FileAttributes fileAttributes);
FileInfo
可能以类似的方式工作。值得一提的是,Set-ItemProperty 受到与 attrib 命令相同的限制。如果设置了系统属性,则需要暂时将其删除才能更改其他属性。