Advertisement
Guest User

Fix_permissions.bat

a guest
Jul 23rd, 2019
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. if exist "%temp%\fixpermissions.tmp" goto skip
  3. if "%~nx1"=="" echo Drag and drop a file/folder.&echo.&pause&exit
  4. if NOT "%~nx2"=="" echo Error! Only one file/folder can be processed at once.&echo.&pause&exit
  5. for /f "tokens=1,2 delims=d" %%A in ("-%~a1") do if "%%B" neq "" (set isfolder=1) else if "%%A" neq "-" (set isfile=1)
  6. if exist "%temp%\fixpermissions.isfolder.tmp" del /Q "%temp%\fixpermissions.isfolder.tmp"
  7. if exist "%temp%\fixpermissions.isfile.tmp" del /Q "%temp%\fixpermissions.isfile.tmp"
  8. if "%isfolder%"=="1" type NUL>"%temp%\fixpermissions.isfolder.tmp"
  9. if "%isfile%"=="1" type NUL>"%temp%\fixpermissions.isfile.tmp"
  10. echo.%~dpnx1>"%temp%\fixpermissions.tmp"
  11. :skip
  12. set /P target=<"%temp%\fixpermissions.tmp"
  13. (cd /d "%~dp0")&&(NET FILE||(powershell -noprofile start-process -FilePath '%0' -verb runas)&&(exit /B)) >NUL 2>&1
  14. if exist "%temp%\fixpermissions.tmp" del /Q "%temp%\fixpermissions.tmp"
  15. net file >nul 2>&1
  16. if NOT %ERRORLEVEL% EQU 0 exit
  17. if exist "%temp%\fixpermissions.isfolder.tmp" takeown /R /F "%target%" /D Y
  18. if exist "%temp%\fixpermissions.isfile.tmp" takeown /F "%target%"
  19. if exist "%temp%\fixpermissions.isfolder.tmp" del /Q "%temp%\fixpermissions.isfolder.tmp"
  20. if exist "%temp%\fixpermissions.isfile.tmp" del /Q "%temp%\fixpermissions.isfile.tmp"
  21. icacls "%target%" /reset /T /C
  22. echo.
  23. pause
  24. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement