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



The information in this article applies to:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional

This article was previously published under Q320046

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 Perl Installation Folder\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 -operation

where -operation 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 Folder | File [ Folder | File...] [ -s Computer [ -u Domain\User -p Password]][-owner LOGONUSER|ADMINGROUP][-recurse]

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

    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 ("").

    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 Computer: 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 Domain\User: 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 Password: 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.
    • 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.
  • : 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.
back to the top

Query

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

fileowners.pl Folder| File [ Folder| File...] [ -s Computer [ -u Domain\User -p Password]][-recurse][-format table| list | csv][-v[-unittype B| KB | MB]][-filter "FieldOperatorValue" [-filter "FieldOperatorValue"...]]

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

    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 ("").

    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 Computer: 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 Domain\User: 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.
    • -p Password: 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.
    Both the -p and -u parameters are available only when you use the -s parameter.

  • 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.
  • 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.
  • Both the -v: Use this parameter to add the last modified date and file size (for files only) to the display.
  • 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).
  • Both the -filter "FieldOperatorValue" [-filter "FieldOperatorValue"...]: 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 Folder | File parameter are included in the display.

    To establish more than one criteria, use a separate instance of -filter "FieldOperatorValue" 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 "FieldOperatorValue":
Field Operator Value Example
OWNER = ! User or group name in Domain\User or Computer\User format. "ownertype=domain\administrators"
OWNERTYPE = ! group | user "ownertype=group"
TYPE = ! file | directory "type!file"
SIZE All logical operators NumberUnit "size>1MB"
DATETIME All logical operators The last modified date, where Date is in mm/dd/yyyy format or Date:Time is in mm/dd/yyyy:hh:mm:ss [am|pm] format "datetime>08/01/2002:8:30:00AM"
PATH\FILE =! Valid paths and file names or *. "path\file!c:winnt"


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 password
  • 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 "e:\graphics and images\*.bmp" -owner admingroup

  • 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

  • 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

  • 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

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 Perl Installation Folder\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 Perl Installation Folder\Site\Lib folder.

    NOTE: The default Perl Installation Folder is drive:\Perl, where drive is the drive on which Windows is installed.
  2. 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

REFERENCES

For more information about Fileowners.pl. type fileowners.pl -? at the command prompt, and then press ENTER.

For additional information about how to take ownership of files in Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:

268019 HOW TO: Take Ownership of Files

For more information about the Windows 2000 Resource Kit and the Windows 2000 Resource Kit Supplement 1, visit the following Microsoft Web site: back to the top

Modification Type:MajorLast Reviewed:9/27/2006
Keywords:kbhowto kbHOWTOmaster KB320046 kbAudITPro