Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 2000

Seize File Ownership with Fileman.vbs


RSS
Subscribe to Windows IT Pro | See More Products / Software Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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!

End of Article



Reader Comments
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. <br><br>
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). <br><br>

Charles Ross September 14, 2000


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement