Tuesday, July 28, 2009

Delete or copy files by owner in winXP

Have you ever had the need to copy or delete files which were owned by a certain user?

The Delete-by-Owner (delbyown.exe) Command Line Utility will scan a NTFS or secure Windows Network file system for files which has an owner matching the one specified. Matched files may be copied to a designated location or deleted.

For example, you have just had a staff member leave your organisation. You would like to back up all their files, however many of them are scattered between project folders and programs across the file system. You have no idea which files were created by this user. However as this staff member has their own login, and any files created would be also be owned by them, you can search the file system for files belonging to the staff member and have them copied to a folder for safe keeping.

delbyown -c h:\backup -r -o harryc -e c:\winnt\profiles c:\*.*

On the other hand you have a public access machine and it's common for users to store files or create folders just about anywhere on the machine. You can restrict the ability to do so with normal security permissions, but you don't want to go overboard and decrease productivity. As the machine was prepared as an Administrator and all the software has been installed as Administrator you can delete all files not owned by the Administrators group. You could choose to schedule this action on a regular basis.

delbyown -d -r -o !Administrators -e c:\winnt\profiles c:\*.*

Usage

The Delete-by-Owner utility has the following settings:

Delete/XCopy by Owner V1.01<br />Copyright(C) 2002-2003 Craig.Peacock@beyondlogic.org<br />Usage: delbyown -c [path] -r -o [owner] -e [exclude path] file<br />       delbyown -d -r -o [owner] -e [exclude path] file<br />       delbyown -t -r -o [owner] -e [exclude path] file<br />        -c    Copy Files to [destination path.]<br />        -d    Delete Files.<br />        -t    Test/Display files matching owner.<br />        -e    Exclude [Directory].<br />        -o    Owner [Account/Group Name].<br />                Accepts not operator e.g. !Administrators<br />        -r    Recursive.<br />

The -c copy, -d delete and -t test switches control what operation will be performed. The test switch simply displays the files that match the owner and is a good way of viewing what files will be targeted or simply as to find which files are owned by a certain user.

Quite often you may wish to exclude a directory. e.g if you are deleting stray files which public users have created, you may wish to skip the users' profile. For example c:\winnt\profiles may be excluded on Windows NT machines, and c:\Document and Settings from Windows 2000 and Windows XP Workstations.

The -o switch specifies the owner of the file to match against. All operating system files are normally owned by the Administrators group. As the utility accepts the not operator, you may choose to use -o !Administrators to delete all files not owned (i.e not installed) by the Administrator. This should be a good start to tiding up the machine up.

If no -o switch is specified, the utility will retrieve the security descriptor for all the files, but will not match it with an owner and subsequently perform any operations. This is a good way to test for any corrupt security descriptors. They should be reported with a message such as

Error 0x539 : The security ID structure is invalid.

The utility accepts all the normal wildcards. You may choose to only delete *.doc files owned by cpeacock e.g.

delbyown -d -r -o cpeacock c:\*.doc
or only files in the c:\program files group
delbyown -d -r -o cpeacock "c:\Program Files\"

The -r recursive switch should be self explanatory. It allows the utility to search in any subdirectories it finds.


Download

  • Version 1.02, 18K bytes. (Freeware)



  • No comments:

    Post a Comment