Modify file owner (VBScript)

This code can be found in Chapter 10 of Windows Server 2003 Security Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code transfers ownership of the specified file to the
' user running the script.  If strFile is set to a folder path
' then ownership of all files within the folder will be changed. 
' ------ SCRIPT CONFIGURATION ------
strFile = "<FilePath>"       ' e.g. d:\scripts
strComputer = "<ServerName>" ' e.g. rallen-svr1 or . for local server
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objFile = objWMI.Get("CIM_DataFile.Name='" & strFile & "'")
intRC = objFile.TakeOwnership
if intRC = 0 then
   WScript.Echo "File ownership successfully changed"
else
   WScript.Echo "Error transferring file ownership: " & intRC
end if

This code has been viewed 3377 times.

New from the creators of TechTasks.com: StatSheet.com