Specifications

21
Taking Ownership of Your Files
1
Note that, obviously, this is quite a bit of work. If you only have to do it every once in a
while, it’s not big thing, but if you find you have to take ownership regularly, you’ll prob-
ably want an easier way to go about it. You’ve got it! Listing 1.1 shows a Registry Editor
file that modifies the Registry in such a way that you end up with a Take Ownership
command in the shortcut menu that appears if you right-click any folder and any file.
NOTE
You can find the Registry Editor file (TakeOwnership.reg) on my website at
www.mcfedries.com/Windows7Unleashed.
LISTING 1.1 A Registry Editor File That Creates a Take Ownership Command
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\runas]
@=”Take Ownership”
“NoWorkingDirectory”=””
[HKEY_CLASSES_ROOT\*\shell\runas\command]
@=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administrators:F”
“IsolatedCommand”=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administra-
tors:F”
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@=”Take Ownership”
“NoWorkingDirectory”=””
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@=”cmd.exe /c takeown /f \”%1\” /r /d y && icacls \”%1\” /grant administrators:F /t”
“IsolatedCommand”=”cmd.exe /c takeown /f \”%1\” /r /d y && icacls \”%1\” /grant
administrators:F /t”
To use the file, double-click it and then enter your UAC credentials when prompted. As
you can see in Figure 1.7, right-clicking (in this case) a folder displays a shortcut menu
with a new Take Ownership command. Click that command, enter your UAC credentials,
and sit back as Windows does all the hard work for you!