Created
April 19, 2024 17:12
-
-
Save milnak/e986c954070074a85e796b4a4d7c2add to your computer and use it in GitHub Desktop.
Take ownership of a Windows file or folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
FOR /f "usebackq" %%f IN (`whoami.exe /priv`) DO IF %%f.==SeTakeOwnershipPrivilege. GOTO :CHKARGS | |
ECHO ERROR: This script must be run as an administrator! | |
GOTO :EOF | |
:CHKARGS | |
IF "%~1"=="" GOTO :EOF | |
ECHO About to take ownership of "%~1" . . . | |
PAUSE | |
takeown.exe /f "%~1" /r /d y | |
icacls.exe "%~1" /grant administrators:F /t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment