我想要從腳本中完成相當於here的描述。基本上,我想獲得文件的所有權,並將權限設置爲OWNER /完全控制。如何使用WMI更改文件權限?
在我看來,從VBS腳本使用WMI是最便攜的方式。也就是說,我想避免xcacls,icacls和其他需要下載的工具,或者僅在某些版本的Windows上受支持。
圍繞谷歌搜索後,我發現這個代碼取得所有權:
'connect to WMI namespace on local machine
Set objServices =
GetObject("winmgmts:{impersonationLevel=impersonate}")
'get a reference to data file
strFile = Wscript.Arguments(0)
Set objFile = objServices.Get("CIM_DataFile.Name='" & strFile & "'")
If objFile.TakeOwnership = 0 Then
Wscript.Echo "File ownership successfully changed"
Else
Wscript.Echo "File ownership transfer operation"
End If
我仍然缺少的是設置權限,並讓它在相對路徑的工作件。