Take Ownership and Full Control of Folders in Vista

18 December, 2008 · 1 minute to read

Take Ownership and Full Control of Folders in Vista

Every now and then an automatic update fails and leaves a directory in the c: drive with a Guid for a name, along the lines of C:\3baf1f42abd933d331f0d49f. The most annoying thing about these is that you can't delete them, even when running as administrator. This is because the SYSTEM account owns them and no-one else has any permissions on them.

To manually delete them, you need to take ownership and then give yourself permission on every folder and file individually. This obviously would take forever, so a scripting solution is required. I finally came up with this solution:

1.    Run PowerShell as administrator.
2.    Navigate into the root of the folder to process.
3.    Take ownership of all the files and folders by running

gci -r | %{takeown /f $_.FullName}
This gets all files and folders below the current directory, then for each one runs takeown filename. Takeown is a utility which comes with Vista.
 

4.    Once you have ownership you need to run icacls on all the files to get permissions on them. icacls is the Vista and Server 2008 replacement for xcacls. The command to run is:

gci -r | %{icacls $_.FullName /grant:r username:F}
username is either you log on name on a stand-alone machine or domain\accountname in a domain.

5.    Once you have permissions you can then run del -r

I found most of this information from Christopher Atkins blog.


 

 

Richard Willis headshot

Written by Richard Willis

Managing Director / Founder

Richard started SalamanderSoft in 2007 after a successful career as a software developer. Wanting to start his own company and with experience in integrating school systems he set out to build the best integration system for schools and to exceed customer expectations. He starting out on his own, doing all the coding, support and sales until finally the growing number of customers meant he needed to start growing the team. He is still heavily involved in coding the core Integration Suite product in addition to running the company and being the first point of contact for prospective customers.

Copyright © 2020 SalamanderSoft Limited