Skip navigation

Modify File Ownership

A free tool can help you transfer ownership

Downloads
45812.zip

One of the most common questions I get in regard to data migration deals with file ownership, which is often lost during copy operations. Robocopy XP010 (the most recent version of the Microsoft Windows Server 2003 Resource Kit tool) supports NTFS data copies that include file-ownership information, but other migration utilities might not. If you use the Creator Owner group to grant permissions, losing file-ownership information during the data-transfer process can threaten file security; a quick and easy way to reassign ownerships to the transferred files can be a lifesaver. You might also run into situations in which you want to reassign ownership during a transfer—for example, when you transfer a file whose owner no longer exists in the organization.

We've all been trained to believe that under Windows NTFS, ownership can only be taken, not assigned, but in fact, several utilities can reassign ownership in a file structure. Let's take a look at the process of reassigning ownership throughout a data structure by using Alexander Frink's free Chown tool, which you can download at http://wwwthep.physik.uni-mainz.de/~frink/nt.html. (See the sidebar "Ownership-Management Tools" for information about other available tools.)

Using Chown
To view the Chown online Help, run chown.exe, with no specified arguments, in a command-shell window. (The chown.zip file also contains a readme.html file that gives additional details about using the tool.) The syntax of the command is

chown.exe \[-r\] \[-q\] \[-v\] \[-s\] \[-d domain | machine\] owner files

The tool supports several optional switches. The -r (recursive) switch recurses subdirectories. The -q (quiet) switch sets Chown to restrict its output to reporting only fatal errors, whereas the -v (verbose) switch causes Chown to print information about all its actions. You can use the -s (skip) switch to skip directories in the path you specify and apply ownership change to files only. You can use the -d domain | machine switch to specify the domain or machine to which the new owner belongs. The two required parameters are owner, which specifies the file's (or files') new owner, and files, which specifies the file or files to be modified. The files parameter can contain the asterisk (*) and question mark (?) wildcard characters. If spaces exist in the file path, enclose the path in double quotes (").

The first thing that you need to decide is how you're going to have ownership flow down through the files and folders in your data structure. When you have one folder, you can use the command shown in the following example:

chown.exe -r Sales\RLewis "\\salessrv1\publicfoldersrlewis\*.*"

This command gives ownership of all files in the specified folder to RLewis.

When you have a series of user folders to which you want to apply different ownerships, you'll need to create a text file that maps a user ID to each of the target folders. Create a comma-separated value (CSV) file called MappingList.txt and populate the file by putting each user ID&150;target folder pair on a separate line with a comma between the ID and folder, as Listing 1 shows. After you've created MappingList.txt and saved it to a convenient location that has no spaces in its path, you can either create a ChangeOwnership.bat file that contains the code that Listing 2 shows, or (as the code is only one line) you can run that code directly from the command line. Specify the location in which you saved MappingList.txt. If you choose the latter option, be sure to substitute single percent-sign iterators (%i and %j) for the dual percent-sign iterators (%%i and %%j) that the code in Listing 2 uses.

The only limitation I've discovered in Chown is that the tool has some difficulty locating local group accounts, and if you preface the user account with the server name, you receive an Unknown local user error message. For example, if you were working on a system called Work1 and wanted to change ownership to the local Administrator account, you'd need to use the command syntax

chown.exe -r Administrator "\\salessrv1\folderA\Test\*.*"

instead of

chown.exe -r Work1\Administrator \\salessrv1\folderA\Test\*.*

If you wanted to change the ownership to a domain account, you'd use the syntax

chown.exe -r Sales\RLewis \\salessrv1\folderA\Test\*.*

Resolve Ownership Issues
You can use tools such as Chown to assign file ownerships when that information has been lost or needs to be reset for some other reason. Take a look at this tool and the others I mention in "Ownership-Management Tools" and arm yourself with techniques to resolve ownership problems on your file and folder structures.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish