Microsoft KB Archive/320046

= HOW TO: Use the File Ownership Script Tool (Fileowners.pl) in Windows 2000 =

Article ID: 320046

Article Last Modified on 10/30/2006

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition

-



This article was previously published under Q320046



IN THIS TASK
SUMMARY System Requirements for Fileowners.pl
 * Source Computer
 * Target Computer

Overview of Fileowners.pl
 * Takeown
 * Query

Examples Troubleshooting REFERENCES



SUMMARY
This step-by-step article describes how to use the File Ownership Script tool (Fileowners.pl) to display and change the owner of folders and files on NTFS volumes of local and remote Microsoft Windows 2000-based computers.

The File Ownership Script tool is available in Microsoft Windows 2000 Resource Kit Supplement 1. Use this script tool to perform the following tasks:
 * Take ownership of files and folders on NTFS volumes.
 * Query the owners of files and folders on NTFS volumes.

The information that Fileowners.pl displays corresponds to the information that appears on the Owner tab of the Properties dialog box of a folder or file. To view this information, follow these steps:
 * 1) Start Windows Explorer.
 * 2) Right-click a folder or file, and then click Properties.
 * 3) Click the Security tab, click Advanced, and then click the Owner tab.

back to the top

System Requirements for Fileowners.pl
Fileowners.pl runs on a source computer and acts on a target computer. (The target computer can be the same computer as the source computer, or it can be a different computer than the source computer). Before you can use this script tool to display or change the ownership of folders and files on NTFS volumes of local or remote computers, the requirements shown later in this article must be met.

back to the top

Source Computer Requirements

 * The computer is running either Windows 2000 Professional or Windows 2000 Server.
 * ActiveState ActivePerl Build 521 is installed. This program is available in the Windows 2000 Resource Kit.

The computer must also be correctly configured to run the Perl scripts that are included in the Windows 2000 Resource Kit Supplement 1. The Resource Kit WMI provider module, Wmi.pm, must be in the \Site\Lib\W2rk folder. The Resource Kit Setup program typically creates the W2rk folder and copies the Wmi.pm file to this folder.

If the W2rk folder is not automatically created during Setup, you can manually create it, and then configure the environment in which to run Fileowners.pl. For more information about how to do this, see the Troubleshooting section later in this article.
 * You are logged on by using a user account that is a member of the Administrators group on the target computer.

back to the top

Target Computer

 * The computer is running either Windows 2000 Professional or Windows 2000 Server.
 * The computer contains volumes formatted with the NTFS file system.

back to the top

Overview of Fileowners.pl
Fileowners.pl uses the following general syntax:

fileowners.pl

where  is one of the following commands that you can pass to the script. The following list describes each operation that you can use with Fileowners.pl:

-takeown: Use this operation to take ownership of folders and files.

-query: Use this operation to search for the owners of folders and files.

Each operation uses its own syntax.

back to the top

Takeown
The fileowners.pl -takeown statement uses the following syntax:

fileowners.pl -takeown  |   [   |  ...] [ -s   [ -u   -p  ]][-owner LOGONUSER|ADMINGROUP][-recurse]

The parameters that you can use with fileowners.pl -takeown are:    |   [   |  ...]: Use this parameter to specify the folder or file that you want to take ownership of using the following format: :\ \.

You can use the wildcard character (asterisk) to designate target files or folders. If you want to specify two or more folders or files, separate each item with a space. If the folder or file name contains a space, enclose the folder or file name and path with quotation marks (&quot;&quot;).

When the file or folder is on a volume that is not mapped to the local computer, use the relative path (the path as seen from the remote computer). -s : Use this parameter to specify the name or IP address of a remote computer. If you omit this parameter, the local computer is specified.  -u : Use this parameter to specify the user account with which to run Fileowners.pl. By default, if you omit this parameter, Fileowners.pl uses system permissions. If you use this parameter, you must also use the -p parameter to provide the user's password. -p : Use this parameter to specify the password of the user account that is specified by the -u parameter. The -p parameter is required when you use the -u parameter.

NOTE: Both the -p and -u parameters are available only when you use the -s parameter.

 : Both the -owner LOGONUSER | ADMINGROUP: Use this parameter to specify whether you are taking ownership as a user or on behalf of the Administrators group. By default, if you omit this parameter, Fileowners.pl uses LOGONUSER.  LOGONUSER: User this parameter to take ownership of the folder or file as a user. By default, the user who is currently logged on to the local computer takes ownership. When the -u parameter is used, the specified user account takes ownership.</li> ADMINGROUP: Use this parameter to take ownership of the folder or file on behalf of the Administrators group. By default, the Administrators group on the local computer takes ownership. When the -s parameter is used, the Administrators group on the remote computer takes ownership of the remote object.</li></ul> </li> : Both the -recurse: Use this parameter to extend the command to all child objects of the specified folder. By default, if you omit this parameter, you take ownership of only the specified folders and files. Subfolders and the files contained in them are not affected.</li></ul>

back to the top

Query
The fileowners.pl -query statement uses the following syntax:

fileowners.pl |   [  |  ...] [ -s   [ -u   -p  ]][-recurse][-format table| list | csv][ [-unittype B| KB | MB]][-filter  [-filter ...]]

The parameters that you can use with fileowners.pl -query are the following:    |   [   |  ...]: Use this parameter to specify the folder or files whose owners are displayed by using the following format: :\ \.

You can use the wildcard character (asterisk) to designate target files or folders. If you want to specify the owners of two or more folders or files, separate each item with a space. If the folder or file name contains a space, enclose the folder or file name and path with quotation marks (&quot;&quot;).

When the file or folder is on a volume that is not mapped to the local computer, use the relative path (the path as seen from the remote computer).</li> -s : Use this parameter to specify the name or IP address of a remote computer. If you omit this parameter, the local computer is specified.  -u : Use this parameter to specify the user account with which to run Fileowners.pl. If you omit this parameter, Fileowners.pl uses the permissions of the currently logged-on user. If you use this parameter, you must also use the -p parameter to provide the user's password.</li> -p : Use this parameter to specify the password of the user account that is specified by the -u parameter. The -p parameter is required when you use the -u parameter.</li></ul>

Both the -p and -u parameters are available only when you use the -s parameter.

</li> Both the -recurse: Use this parameter to add all child objects of the specified folder to the display. If you omit this parameter, only the specified folder and files are included in the display.</li> Both the -format table|list| csv: Use this parameter to specify the output format. If you omit this parameter, Fileowners.pl uses the table format, by default.</li> Both the -v: Use this parameter to add the last modified date and file size (for files only) to the display.</li> Both the -unittype B|KB| MB: Use this parameter to specify the unit of disk space that is used to display the file size. By default, if you omit this parameter, Fileowners.pl uses kilobytes (KB).</li> Both the -filter  [-filter ...]: Use this parameter to specify the criteria for folders and files that are included in the display. If you omit this parameter, all items that are specified in the   |   parameter are included in the display.

To establish more than one criteria, use a separate instance of -filter for each criteria that you want to specify, and separate each instance with a space. Fileowners.pl displays only those files and folders that meet all of the criteria.

The following table lists the operators and values that are available for each field that is used with the -filter parameter, and an example of each :</li></ul>

back to the top

Examples
 To run Fileowners.pl by using the User1 account to take ownership of the E:\Reports\Stats.doc file on a remote computer named Server8 in the Corp domain, type the following line at the command prompt, and then press ENTER: fileowners.pl -takeown e:\reports\stats.doc -s server8 -u corp\user1 -p </li> <li>To take ownership of all bitmap files (.bmp) in the E:\Pictures and E:\Graphics and Images folders on behalf of the Administrators group on the local computer, type the following line at the command prompt, and then press ENTER:

fileowners.pl -takeown e:\pictures\*.bmp &quot;e:\graphics and images\*.bmp&quot; -owner admingroup

</li> <li>To take ownership of all folders and files on volumes X and Y, type the following line at the command prompt, and then press ENTER:

NOTE: You can use this method to take ownership of objects on several computers. In this example, the X drive on the local computer is mapped to the C drive of a remote computer named Server4, and the Y drive on the local computer is mapped to the C drive of a remote computer named Server10. If the remote volume is mapped to a drive on the local computer, you can specify the mapped drive letter in the file path. You do not have to use the -s parameter to indicate another computer.

fileowners.pl -takeown x: y: -recurse

</li> <li>To display the owner of the Expenses.doc file in the D:\Finance folder in list format, type the following line, and then press ENTER:

fileowners.pl -query d:\finance\expenses.doc -format list

</li> <li>To display the owners of all files in the C:\Corpdocs folder and its subfolders, include the date that the file was last modified and file size in the display, and redirect the output to a file named Corpdoc.txt in the E:\Docs folder in the default table format, type the following line, and then press ENTER:

fileowners.pl -query c:\corpdocs\*.* -recurse > e:\docs\corpdoc.txt -v

</li></ul>

back to the top

Troubleshooting
When you try to run Fileowners.pl, you may receive the following error message:

ERROR: Wmi.pm is required to run the script.

Copy Wmi.pm from the Resource Kit directory to /Perl/site/lib/W2RK.

This behavior may occur if the computer is not correctly configured to run the Perl scripts included in the Windows 2000 Resource Kit Supplement 1. To use Fileowners.pl, the W2rk folder must exist in the \site\lib folder and it must contain the Wmi.pmi file.

To resolve this problem, manually configure the environment in which to run Perl scripts. To do this, follow these steps:
 * 1) Create a folder named W2rk in the  \Site\Lib folder.

NOTE: The default  is  :\Perl, where   is the drive on which Windows is installed.
 * 1) Copy the Wmi.pmi file from the folder in which the Windows 2000 Resource Kit is installed (by default, it is Program Files\Resource Kit) to the W2rk folder that you created in step 1.

back to the top

<div class="references_section">