@echo off

IF %1.==. GOTO USAGE

if /I %1 == %SystemDrive% goto nosystemdrive
if /I %1 == %SystemDrive%\ goto nosystemdrive

if NOT EXIST %1 (
  echo ERROR: file or directory not found!
  exit /b
)

echo removing access rights for Users on [ %1 ] ...

if EXIST %1\* (

  echo *** DIRECTORY mode ***
  takeown /F %1 /R /A /D Y 1>nul
  icacls %1 /inheritance:r
  icacls %1 /grant Administrators:F /t /c /l /q
  icacls %1 /remove Users /t /c /l /q

) else (

  echo *** FILE mode ***
  takeown /F %1 /A  1>nul
  icacls %1 /inheritance:r
  icacls %1 /grant Administrators:F /c /l /q
  icacls %1 /remove Users /c /l /q

)
echo.
icacls %1
GOTO END

:nosystemdrive
echo ERROR: cannot use the SystemDrive!
GOTO END

:USAGE
echo "usage: %0 <path>"

:END

