I want to do the equivalent of what is described here from a script. Basically, I want to take responsibility for the file and set permissions for OWNER / Full Control.
It seems to me that using WMI from a vbs script is the most portable way. That is, I would like to avoid xcacls, icacls and other tools that require downloading or are only supported in some versions of windows.
After searching on Google, I found this code to go to the property:
'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
Parts that I still miss set permissions and work on relative paths.
source
share