Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 2007

The Lowdown on Takeown

Check out this quick, simple-syntax tool for taking ownership of files
RSS
Subscribe to Windows IT Pro | See More Administration Articles Here | Reprints
Or get the Monthly Online Pass—only $5.95 a month!

Ever since Windows Vista appeared, readers have repeatedly sent me the same question: "Why can't I modify the HOSTS file?" Many people modify the

HOSTS file—located in \windows\system32\drivers\etc—to protect the system from sites that promote the spread of malware. However, Vista blocks this kind of modification. By default, Vista administrators don't have permission to delete most files in the \windows directory—nor do they own those files. Therefore, to modify HOSTS, you first need to take ownership of the file. You've been able to take ownership of a file from the GUI ever since Windows NT 3.1, but that built-in capability isn't terribly useful for remote administration. Fortunately, Vista and Windows Server 2003 include a new command-line tool called Takeown that lets you take ownership of files or folders.

How It Works
Takeown's basic syntax looks like

takeown /f <file or folder name> 

You'll probably need to run Takeown with your full administrative powers, and Vista's User Account Control might get in the way of that. Therefore, before you try to run Takeown, go to Start, All Programs, Accessories, Command Prompt—as you've probably done many times. But this time, in Vista, right-click the Command Prompt icon and choose Run as administrator. After you verify the action by clicking Confirm, you'll have what Vista refers to as an elevated command prompt.

You can now take ownership of your system's HOSTS file:

takeown /f C:\windows\system32\drivers\etc\hosts 

(This command assumes that you have Vista on the C drive, of course. If Vista actually resides somewhere else, just change the drive letter.) Vista will respond with something like

SUCCESS: The file (or folder): "C:\windows\ 
  system32\drivers\etc\hosts" now owned by user 
  <youraccountname>. 

At this point, you can assign yourself write permissions to the HOSTS file and make changes.

Takeown has more options than just /f, of course. To take ownership of an entire tree of folders and files, you can add the /r option. Thus, if you wanted to take ownership of a folder named C:\documents, as well as any files and folders inside C:\documents, you'd type

takeown /f C:\documents /r

Tackling an Annoyance
If you've ever tried to take ownership of a tree of folders, you might have run into something of an annoyance—namely, Windows' tendency to ask if you really, truly want to take ownership. Suppose, for example, that you not only don't own C:\documents but you also don't have permission to look in C:\documents. In that case, taking ownership of C:\ documents wouldn't equip you to take control of any subfolders in C:\documents for the simple reason that although you would now own C:\documents, you would still lack the NTFS permissions necessary to list its subfolders.

Feasibly, you could take ownership of each directory, one at a time, then add a list folders permission to that folder, which would let you see the subfolders in that folder, which in turn would let you take ownership of the subfolders. Thankfully, such manual labor isn't necessary: Whenever you use the /r option with Takeown, the command pauses at each folder and asks whether you'd like Takeown to add the list folders permission to that folder's NTFS permissions. That's a nice touch, but it means that taking control of a folder containing dozens of folders could get a bit tedious.

The good news is that you can configure Takeown so that it doesn't ask you if you want to add the list folders permission and instead just assumes that you'll answer yes or no. To do that, you use the /d option, followed by a y or an n. So, to take ownership of C:\documents and all its subfolders, while granting yourself the list folders permission, you'd type

takeown /f C:\documents /r /d y 

Note, however, that in the process of giving you permission to list folders, Takeown /r first removes any other explicit permissions on that folder! Inherited permissions seem unaffected in my tests, however.

Own It!
To my knowledge, Windows has previously offered only one command-line tool to take ownership: the resource kit's Subinacl tool. Subinacl is a powerful tool, but its syntax can require some study. Takeown offers a command-line alternative with simple syntax.

End of Article



Reader Comments
It appears that Takedown doesn't actually exist. I searched a Vista, W2K3, and W2K8 computer and none of them had it.

masonth@comcast.net September 30, 2007 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

How can I uninstall the Microsoft Java Virtual Machine (JVM) from Windows XP?

...

What service packs and fixes are available?

...


Windows OSs Whitepapers Replay for Exchange: Enterprise Protection and an Affordable Price

Are You Satisfied?

A Preliminary Look at Deployment Plans for Microsoft Windows Vista

Related Events Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Disaster Recovery and Backup

A Guide to Windows Certification and Public Keys

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Critical Challenges of ESI & Email Retention
Are you storing too much electronic information? Get expert legal advice and better understanding of what you are required to do as an IT professional.

Become a fan of Windows IT Pro on Facebook!
Join us on Facebook and be a fan of Windows IT Pro!

Sustainable Compliance: Are You Having a Resource Crisis?
Read this white paper to examine trends in compliance and security management and review approaches to reducing the cost and operational burden of compliance.

Rev Up Your IT Know-How with Our Recharged Magazine!
The improved Windows IT Pro provides trusted IT content with an enhanced new look and functionality! Get comprehensive coverage of industry topics, expert advice, and real-world solutions—PLUS access to over 10,000 articles online. Order today!

Get It All with Windows IT Pro VIP
Stock your IT toolbox with every solution ever printed in Windows IT Pro and SQL Server Magazine plus bonus Web-exclusive content on hot topics. Subscribe to receive the VIP CD and a subscription to your choice of Windows IT Pro or SQL Server Magazine!



Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.
Windows IT Pro Home Register About Us Affiliates / Licensing Media Kit Contact Us/Customer Service  
SQL Connected Home IT Library SuperSite FAQ Wininfo News
Europe Edition Office & SharePoint Pro Windows Dev Pro Windows Excavator 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing