Windows 10 How grant folder from command prompt

  • Thread starter Thread starter drjackool
  • Start date Start date
D

drjackool

Hi
I need to redirect Windows logs folder by mklink command but before creating a link the source folder must be deleted and when I using rmdir command, it reports access denied. To solving this problem I have to change folders permission manually. But I need a command to change it from command prompt before calling rmdir command. I found icacls to changing folder security options but I do not know how set parameters because it is complex command.

Please help


Following is my batch file to redirect some Windows directories:




@ECHO OFF

CLS



ECHO *******************************************************************************************

ECHO * This file applies some settings that improves the system performance *

ECHO * and increases SSD life span *

ECHO *******************************************************************************************

ECHO.

PAUSE



ECHO {************ Creating directories redirection ************}



:: Set redirection path to this variable

SET REDIR_PATH="D:\SysRedirection"



IF EXIST "%REDIR_PATH%" (RMDIR /S /Q "%REDIR_PATH%")



:: Logs

SC stop "EventLog"

CALL :Redirect "C:\Windows\Logs", "%REDIR_PATH%\WinLogs"

CALL :Redirect "C:\Windows\System32\LogFiles", "%REDIR_PATH%\Sys32Logs"

CALL :Redirect "C:\Windows\System32\winevt\Logs", "%REDIR_PATH%\EventLogs"

SC start "EventLog"



ECHO {************************** Done **************************}

PAUSE



EXIT /B %ERRORLEVEL%




:: This function deletes the source folder and creates a junction link at target


:: Param1: Source folder, Param2: Target


:Redirect

ECHO ============================================================

ECHO Redirecting %~1

ECHO

IF EXIST %~1 (

RMDIR /S /Q %~1

:: Check if folder exist yet, ask the user to delete it manually

IF EXIST %~1 (

ECHO.

ECHO [!!!NOTE!!!] Please delete %~1 manually before continue.

PAUSE

)

)



MKDIR %~2

MKLINK /J %~1 %~2

ECHO.

EXIT /B 0

Continue reading...
 
Back
Top