When using CIM_DataFile from WMI, you may notice differences in behavior when running locally versus remotely. Specifically, permissions will be handled differently when run remotely. An example scenario would be that of an Administrator that does not have full access to a file location, specifically being denied DELETE rights. Below is an example script that uses CIM_DataFile to rename a file:
strComputer = WScript.Arguments(0)
strFile = WScript.Arguments(1)
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Name = " _
& "'c:\\" + strFile + "'")
For Each objFile in colFiles
errResult = objFile.Rename("c:\" + strFile + ".old")
Next
If this script example is run locally, access will be denied as expected. However, if the same script is run remotely, the delete or rename operation will succeed, which is not expected.
strComputer = WScript.Arguments(0)
strFile = WScript.Arguments(1)
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Name = " _
& "'c:\\" + strFile + "'")
For Each objFile in colFiles
errResult = objFile.Rename("c:\" + strFile + ".old")
Next
If this script example is run locally, access will be denied as expected. However, if the same script is run remotely, the delete or rename operation will succeed, which is not expected.