How to change ownership of a file in Windows 10

19,746

Try:

Taking ownership of a file or folder from command line

Open an elevated Command Prompt window.

To do so:

a. Go to > Start > All Programs > Accessories

b. Right-click on Command Prompt, and then click Run as Administrator.

c. Type the following command and press Enter key:

takeown /f [path to folder] /r /d y

d. Then assign the Administrators group Full Control Permissions for the folder, use this command and hit Enter key:

icacls [path to folder] /grant administrators:F /T 

The /T parameter is added so that the operation is carried out through all the sub-directories and files within that folder.

Share:
19,746

Related videos on Youtube

markspace
Author by

markspace

Updated on September 18, 2022

Comments

  • markspace
    markspace over 1 year

    I have a file that's created by a program, and apparently an interaction with the system and Google Backup & Sync somehow scrambles the owner and permissions of the file. (The owner shows up as either "Unknown" or "Unable to display current owner", depending on where I look at it.)

    I need to reclaim ownership of the file.

    The standard method (from the File Explorer right click, Properties, Security tab, Advanced, Change Owner) doesn't work because I don't have permission to do that. Basically I need super user access on my own system so I can override what the OS thinks and actually administrate the file.

    Anyone got a clue? Rebooting seems to clear the issue but that's a crappy solution. I have a Cygwin shell on this system if that helps. I'd prefer to not have to download any special utilities unless the source is very trustworthy.

    Edit The problem re-occured. So far I'm not able to set the owner of the offending files:

    C:\Users\Brenden>icacls "C:\Users\Brenden\Google Drive\proj\tempj8\build   \classes\quicktest\AbstractTest.class" /SETOWNER "%username%" /c
    C:\Users\Brenden\Google Drive\proj\tempj8\build\classes\quicktest\AbstractTest.class: Access is denied.
    Successfully processed 0 files; Failed processing 1 files
    
    C:\Users\Brenden>
    

    This command fails too:

    C:\WINDOWS\system32>takeown /F "C:\Users\Brenden\Google Drive\proj\tempj8\build\classes\quicktest\AbstractTest.class"
    ERROR: Access is denied.
    
    C:\WINDOWS\system32>
    
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style almost 6 years
      markspace - Try these two commands and tell me if this helps solve: icacls "C:\folder\path\file.txt" /SETOWNER "%username%" /C and then takeown /F "C:\folder\path\file.txt".... If this helps, tag me back as @PimpJuiceIT and I'll add this information along with some additional detail plus some reference sources for further learning.
    • markspace
      markspace over 5 years
      The first command you gave me didn't work: see my edit but it says "Access is denied." Any other ideas? @PimpJuiceIT
    • markspace
      markspace over 5 years
      @PimpJuiceIT Just tried takeown by itself in a command prompt and it fails also.
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 5 years
      Read over this post and look over some of the commands if states to run with options and such. I think perhaps running takeown /f "C:\Users\Brenden\Google Drive\*.*" /r /a /d y and then ICACLS "C:\Users\Brenden\Google Drive\*.*" /reset /T /C /L /Q may help but look over all the thread and what people say does work for some. It's likely a security setting at a higher level up parent folder wise that needs to be reset or whatever but not sure if you could disable inheritance from `"C:\Users\Brenden\Google Drive` and then set the security but another thought I had.
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 5 years
      Oh.... here's the post too by the way: social.technet.microsoft.com/Forums/windows/en-US/…
  • DrMoishe Pippik
    DrMoishe Pippik almost 6 years
    Chris, to make this a self-contained answer, please summarize or quote at least the essentials from that tutorial (and keep the link to that useful article).
  • Chris
    Chris almost 6 years
    I'm on mobile right now, so I'll have to do several edits to meet the guideline. I'll remember that from now on.
  • markspace
    markspace almost 6 years
    I specifically mentioned this in my OP. It doesn't work. At the point where I click Change next to the Owner, it says I'm not allowed to do that. So no doesn't work.
  • Chris
    Chris almost 6 years
    @markspace I'm blind. I'll do some more research when I get back to my computer and I'll update you if I can figure another method, if it's still unsolved. Sorry about that
  • markspace
    markspace over 5 years
    This also says "access denied" even though I ran it as administrator and got the little "Are you sure you want let this app make changes to your device?" pop up.
  • sree
    sree almost 4 years
    The grant administrators full rights didn't work for me, but the reset argument works: icacls found.000 /reset /t.