Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

May 10, 2000 09:25 AM

Seize File Ownership with Fileman.vbs

Windows IT Pro
InstantDoc ID #8748
Rating: (0)
Finally! A command-line tool for changing file ownership

Now and then I need to change ownership of a file that is on an NTFS drive. I can do that with the GUI through My Computer or Windows Explorer (select the file, right-click it, choose Properties from the resulting context menu, choose the Security tab, and click the Ownership button), but as is so often the case, I'd like to be able to do this task from the command line as well.

Windows NT resource kits have long included the Chown utility for changing ownership, but I've never been able to make it work. So, I was excited to find fileman.vbs tucked among the dozens of VBScript routines in the Microsoft Windows NT Server 4.0 Resource Kit Supplement 4.

Fileman.vbs lets you copy, delete, rename, or seize ownership of a file. Command-line tools already exist to copy, delete, and rename files, but I was glad to finally have a command-line ownership tool. The tool is a mite cumbersome, as you'll see. But because it's a script file, you've got the source code, so enterprising readers can address some of fileman.vbs' flaws.

To change a file's ownership, you invoke fileman.vbs:

cscript <scriptpath>\fileman.vbs /T <fullyqualifiedfilename>

The syntax looks straightforward, but kinks exist. First, notice the scriptpath part—you feed the name of the VBScript file to cscript, so you need to provide fileman.vbs' qualified name and location. Because my resource kit files are in C:\ntreskit, my command would begin with cscript c:\ntreskit\fileman.vbs. Second, the /T option is case sensitive. Third, you must specify the fully qualified name of the file that you want to seize ownership of. Typically, when you execute a command from within the same drive and directory as the file on which the command acts, you can omit the file's directory and drive letter. Not here! To take ownership of the names.txt file on D:\myfiles, I'd need to type

cscript c:\ntreskit\fileman.vbs /T d:\myfiles\names.txt

Finally, you can't feed fileman.vbs wildcards—you can't simply tell fileman.vbs to change ownership on *.* and walk away secure in the knowledge that fileman.vbs will take ownership of all the files in a directory. You can work around that limitation, however, with a fairly long For statement.

For those who've not used it, the For command lets you tell NT to repeat a specified command for a group of files. Simplified, the For command looks like

for %f in (*.*) do 
<somecommand> %f

This command causes NT to find all files that meet the criterion in the parentheses—I used *.*, but you could use anything—and to replace %f with each file's name, one at a time. With each replacement, the For command executes the specified command, again replacing %f with the current filename. For example, to tell fileman.vbs to take ownership of every file in a directory named C:\soontobemine, I'd type

for %f in (c:\soontobemine\*.*) do cscript c:\ntreskitfileman.vbs /T %f

Because I specify a drive and directory name in the parentheses, each execution of the specified command includes that drive and directory name, so I don't need to type the drive and directory in the right-hand part of the command. If I wanted to execute the For command from inside C:\soontobemine, then I could have a shorter term in parentheses, but I'd need a longer right-hand portion:

for %f in (*.*) do cscript c:\ntreskit\fileman.vbs /T c:\soontobemine\%f

One final note: If you want to include a For command in a batch file, you must change %f to %%f, as in

for %%f in (c:\soontobemine\*.*) do cscript c:\ntreskit\fileman.vbs /T %%f

Now, readers, what clever soul will modify fileman.vbs script so that it will work on an entire drive, rather than just a directory? One of you, I hope!

Related Content:

ARTICLE TOOLS

Comments
  • Charles Ross
    12 years ago
    Sep 14, 2000

    I read Mark Minasi's This Old Resource Kit: "Seize File Ownership with Fileman
    .vbs" (June 2000) about changing NTFS file ownership from the command line. The Microsoft Windows NT Server 4.0 Resource Kit provides a much simpler tool for accomplishing this task: Subinacl.


    The Microsoft article "Cannot Remove Folder Without Being Prompted" (http://support.microsoft.com/support/
    kb/articles/q246/0/23.asp) contains a good description of how the tool works. I've used Subinacl successfully, and you can use it to work on an entire drive
    (a capability the author mentioned he wanted).

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.