授予管理員權限並遍歷所有文件和資料夾的批次腳本

授予管理員權限並遍歷所有文件和資料夾的批次腳本

我有這個,很確定它有點苛刻,但可以完成工作,在驅動器上運行時給我驅動器上文件和文件夾的所有權限,現在我需要幫助讓它進入子目錄,所以我不需要將bat腳本複製到每個資料夾中並必須運行它。

takeown /f *
icacls * /grant Administrator:F
icacls * /grant Administrators:F
icacls * /grant SYSTEM:F
icacls * /grant "Authenticated Users":F

我該如何讓它遞歸地遍歷驅動器?

答案1

簡短回答: 加入/t(i)cacls

長答案:

這是當我希望任何用戶都可以存取該文件時使用的腳本。它包括對每個標誌的作用的註釋。只需將其放入資料夾中某處的批次檔中即可%AppData%

REM --v2 -----------------------------------------------------------
takeown /r /d y /f %1
icacls %1 /t /grant Everyone:F

REM takeown /r /d y /f will set the owner to the Administrators group recursively.
REM /t makes it recursive
REM /grant Sets the permision to the following user, replaces existing permissions for the specified uesr.
REM :f Grants full controll permission.
REM ----------------------------------------------------------------

REM --v1 -----------------------------------------------------------
REM cacls %1 /t /e /g Everyone:f

REM /t makes it recursive
REM /e Edits the ACL instead of replaceing it
REM /g Grants permissions to the following users
REM :f Grants full controll permission.
REM ----------------------------------------------------------------

然後%AppData%\Microsoft\Windows\SendTo建立批次腳本的快捷方式。

編輯該捷徑的屬性,然後前往Advanced...並選取該框Run as Administrator.

在此輸入影像描述

現在,您將擁有一個名為「您執行的任何檔案或資料夾」的right click menu -> Send To項目,該項目將具有「Everyone」群組授予的權限。如果您對資料夾執行此操作,它將遞歸地遍歷該資料夾並將權限套用至該資料夾中的所有子層級。Fix PermissionsSend ToFull Access


我將批次檔保存在%AppData%資料夾中,因為我位於網域中,這使其成為我的漫遊設定檔的一部分,因此它將在我連接到的任何電腦上開啟並準備使用。

答案2

這適用於網路共用嗎?

Takeown /f *
icacls * /grant Administrator:F
icacls * /grant Administrators:F
icacls * /grant SYSTEM:F
icacls * /grant "Authenticated Users":F
icacls * /grant "doamin\users":R

相關內容