Transfer ownership of a file (Perl)
This code can be found in
Chapter 8 of Windows XP Cookbook
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the Perl code from this site.
# From the book "Windows XP Cookbook"
# ISBN: 0596007256
# 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 ------
use Win32::OLE;
$strFile = '<FilePath>';
# e.g. d:\scripts
$strComputer = '<ComputerName>';
# e.g. rallen-svr1 or . for local system
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objFile = $objWMI->Get('CIM_DataFile.Name=\'' . $strFile . '\'');
$intRC = $objFile->TakeOwnership;
if ($intRC == 0) {
print "File ownership successfully changed\n";
}
else {
print 'Error transferring file ownership: ' . $intRC, "\n";
}
|
This code has been viewed 739 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|