Board logo

标题: [求助][補問問題]XCACLS安全性修改(用FOR組合和呼叫TXT設定) [打印本页]

作者: XZ     时间: 2008-5-27 00:32    标题: [求助][補問問題]XCACLS安全性修改(用FOR組合和呼叫TXT設定)
需求 列出資架夾清單->列出群組->選擇安全性 -> 完成 我只能個別寫出來不會統合起來 請問要如何將下面的批次檔統合起來 謝謝
set ListFlodercount=100
set ListGroupcount=100
for /f "delims=" %%a in ('dir *. /b') do (set /a ListFlodercount+=1&&call set ListFloder%%ListFlodercount%%=%CD%\%%a&&call SET MaxFloderNumber=%%ListFlodercount%%)

for /f "skip=1 delims= " %%a in ('wmic group list brief') do (set /a ListGroupcount+=1&&call set ListGroup%%ListGroupcount%%=%%a&&call SET MaxGroupNumber=%%ListGroupcount%%)

echo.F  Full control
echo.M  Modify
echo.X  read & eXecute
echo.L  List folder contents
echo.R  Read
echo.W  Write
set access=
set /p access=Type F or M or X or L or R or W:

xcacls.vbs "ListFloder%%ListFlodercount%%" /g "ListGroup%%ListGroupcount%%":%access%
假設資料夾目錄為: 第一資料夾 第二資料夾 第三資料夾 第四資料夾 假定群組為: A群組 B群組 C群組 假定需求: 第一資料夾 A群組 權限 R 第一資料夾 B群組 權限 W 第一資料夾 C群組 權限 F 第二資料夾 A群組 權限 R 第二資料夾 B群組 權限 R 第二資料夾 C群組 權限 F 第三資料夾 A群組 權限 W 第三資料夾 B群組 權限 W 第三資料夾 C群組 權限 F 第四資料夾 A群組 權限 F 第四資料夾 B群組 權限 F 第四資料夾 C群組 權限 F XCACLS.vbs 說明 support.microsoft.com/kb/82575 ... [ Last edited by XZ on 2008-5-31 at 12:28 AM ]

作者: mkd     时间: 2008-5-27 16:07
@echo off
for /d %%a in (*) do (
	for /f "skip=4 tokens=* delims=*" %%i in ('net localgroup') do (


		call cscript xcacls.vbs %%xxx%%%%xccess%%
		
		echo Folder:%%a
		echo  Group:%%i
		echo.
		echo.F  Full control
		echo.M  Modify
		echo.X  read ^& eXecute
		echo.L  List folder contents
		echo.R  Read
		echo.W  Write
		set xccess=
		set /p xccess=Type F or M or X or L or R or W:


		set xxx="%%a" /e /g "%%i":
		)
)
%access% %a %xccess%

作者: XZ     时间: 2008-5-27 20:14
感謝您 可以正常執行 但是否這個批次檔有一個問題,一個缺點 問題點: 要是某一群組不需要此資料夾的權限,無法跳過 缺點: 此方次效率不高 若用呼叫其他的TXT檔的方式然後自動進行設定是否可行? 如: FloderSetup.txt
A群組,B群組,C群組
第一資料夾,R,W,F
第二資料夾,R,R,F
第三資料夾,W,W,F
第四資料夾,F,F,F

作者: XZ     时间: 2008-5-27 21:12
接續上頭問題 對不起..各位前輩們 我只會這到這樣 請大家幫幫忙 如合自動的往下一個群組執行 因為這樣子只會修改 A群組的安全性 B群組..C群組之後不會執行 還有就是 安全性與群組資料夾在不同行 @@a 沒辦法代入下面這行指令
call cscript xcacls.vbs "%%f" /g "%COMPUTERNAME%%%g":%%s
還是我從頭開始就已經錯了ˇˇ
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION


dir /b *. > FloderList.txt
for /f " tokens=1 delims=," %%f in (FloderList.txt) do ( 
for /f " tokens=1 delims=," %%g in (GroupList.txt) do (
echo %%f-%%g
)
)
)

for /f "skip=1 tokens=2 delims=," %%s in (SecureList.txt) do (echo %%s)
)

rem call cscript xcacls.vbs "%%f" /g "%COMPUTERNAME%%%g":%%s
結果:
E:\zz>zz.bat
第一資料夾-A群組
第三資料夾-A群組
第二資料夾-A群組
第四資料夾-A群組
R
R
W
F
SecureList.txt
A群組,B群組,C群組
第一資料夾,R,W,F
第二資料夾,R,R,F
第三資料夾,W,W,F
第四資料夾,F,F,F
GroupList.txt
A群組,B群組,C群組
[ Last edited by XZ on 2008-5-27 at 10:10 PM ]

作者: XZ     时间: 2008-5-27 23:12
拜讀論壇內許多文章 我現在能改道這樣 問題一: For 中 a~z 只有26個 要是資料夾和群組加起來超過26個怎麼辦?? 問題2: 要如何自動判斷需要用到幾個變數 要是資料夾的數目便少或便多 這樣子的架構只能修改到前三樣資料夾和群組 問題3: 此批處理有那些需要修改的地方 因為這個是我東湊西拼硬搭出來的 不清楚有無錯誤或會造成不良的結果 請再次協助 謝謝! 批處理:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

for /f " tokens=1-10 delims=," %%u in (GroupList.txt) do (
for /f "skip=1 tokens=1-15 delims=," %%a in (SecureList.txt) do (

echo========================================================
echo 資料夾			群組		安全性
echo %%a		%%u		%%b 
echo %%a		%%v		%%c
echo %%a		%%w		%%d

rem call cscript xcacls.vbs "資料夾" /g "群組":安全性 /e
rem call cscript xcacls.vbs "%%a" /g "%%u":%%b /e
rem call cscript xcacls.vbs "%%a" /g "%%v":%%c /e
rem call cscript xcacls.vbs "%%a" /g "%%w":%%d /e
)
)
結果:
E:\zz>zz
=======================================================
資料夾                  群組            安全性
第一資料夾              A群組           R
第一資料夾              B群組           W
第一資料夾              C群組           F
=======================================================
資料夾                  群組            安全性
第二資料夾              A群組           R
第二資料夾              B群組           R
第二資料夾              C群組           F
=======================================================
資料夾                  群組            安全性
第三資料夾              A群組           W
第三資料夾              B群組           W
第三資料夾              C群組           F
=======================================================
資料夾                  群組            安全性
第四資料夾              A群組           F
第四資料夾              B群組           F
第四資料夾              C群組           F

E:\zz>
備註: SecureList.txt 內容
A群組,B群組,C群組
第一資料夾,R,W,F
第二資料夾,R,R,F
第三資料夾,W,W,F
第四資料夾,F,F,F
GroupList.txt 內容
A群組,B群組,C群組
[ Last edited by XZ on 2008-5-27 at 11:37 PM ]

作者: mkd     时间: 2008-5-28 14:15
for /f "tokens=1-25 delims=," %%B in (SecureList.txt) do (
	for /f "skip=1 tokens=1-26 delims=," %%a in (SecureList.txt) do (
		cacls "%%~a" /t /e /p %%B%%b  %%C%%c  %%D%%d %%E%%e %%F%%f %%G%%g %%H%%h %%I%%i %%J%%j %%K%%k %%L%%l %%M%%m %%N%%n %%O%%o %%P%%p %%Q%%q %%R%%r %%S%%s %%T%%t %%U%%u %%V%%v %%W%%w %%X%%x %%Y%%y %%Z%%z
		)
	exit/b
)
SecureList.txt
A群組:,"B 群 組:",C群組: 第一資料夾,R,C,F 第二資料夾,R,R,F 第三資料夾,C,C,F 第四資料夾,F,F,F

作者: tao0610     时间: 2008-5-28 18:09
按你那个改了一下
@echo off & SETLOCAL ENABLEDELAYEDEXPANSION
:flag
for /f "%flag% delims=" %%a in (SecureList.txt) do (
  set str=%%a&&set str=!str:,= !&set num=1
  if "%flag%"=="" call :lp !str!&set flag=skip=1&goto flag
echo========================================================
echo 資料夾                  群組              安全性
  call :lp1 !str!
)
pause&exit


:lp1
set name=%1&shift
:lp
if not "%flag%"=="" (
  echo %name%              !Group%num%!               %1
  rem call cscript xcacls.vbs "%name%" /g "!Group%num%!":%1 /e
  ) else set Group%num%=%1
shift
if not "%1"=="" set/a num+=1&goto lp

作者: XZ     时间: 2008-5-29 19:25
Originally posted by mkd at 2008-5-28 02:15 PM: [code] for /f "tokens=1-25 delims=," %%B in (SecureList.txt) do ( for /f "skip=1 tokens=1-26 delims=," %%a in (SecureList.txt) do ( cacls "%%~a" /t /e /p %%B%%b ...
感謝 隻所以不用CACAS.exe 因為它不支援 列表的權限.. 不過我也學到了 原來只要這麼短就可以達到相同的需求= =" 看來我要學的路還很遠^^

作者: XZ     时间: 2008-5-29 19:27
Originally posted by tao0610 at 2008-5-28 06:09 PM: 按你那个改了一下 [code] @echo off & SETLOCAL ENABLEDELAYEDEXPANSION :flag for /f "%flag% delims=" %%a in (SecureList.txt) do ( set str=%%a&&set str=!str:,= !& ...
只能說強!!功能達到 請問能大概解釋一下 這樣子寫法 好深奧 看不懂= = 謝謝您 我再努力領悟中

作者: XZ     时间: 2008-5-29 19:54
1.如何加入 將變更安全性失敗的資料夾顯示或輸出成TXT檔 2.如何呼叫 GUI的安全性而不是自定義安全性 因為單參數下 /g "Administrator":W 安全性表設定表 只會單獨勾起 "寫入" 一項 但是正常寫入權限需要勾起 "修改,讀取與執行,清單資料夾內容,讀取,寫入"五項 /g "Administrator":R 安全性表設定表 只會單獨勾起 "讀取" 一項 但是正常寫入權限需要勾起 "讀取與執行,清單資料夾內容,讀取"三項 安全性設定表:
全權控制
修改
讀取與執行
清單資料夾內容
讀取
寫入
特殊權限
XCACLS.VBS說明:
    /G user:GUI         Grant security permissions similar to Windows GUI
                       standard (non-advanced) choices.
   /G user:Perm;Spec   Grant specified user access rights.
                       (/G adds to existing rights for user)

                       User: If User has spaces in it, enclose it in quotes.
                             If User contains #machine#, it will replace
                             #machine# with the actual machine name if it is a
                             non-domain controller, and replace it with the
                             actual domain name if it is a domain controller.

                             New to 3.0: User can be a string representing
                             the actual SID, but MUST be lead by SID#
                             Example: SID#S-1-5-21-2127521184-160...
                                      (SID string shown has been shortened)
                                      (If any user has SID# then globally all
                                       matches must match the SID (not name)
                                       so if your intention is to apply changes
                                       to all accounts that match Domain\User
                                       then do not specify SID# as one of the
                                       users.)

                       GUI: Is for standard rights and can be:
                             Permissions...
                                    F  Full control
                                    M  Modify
                                    X  read and eXecute
                                    L  List folder contents
                                    R  Read
                                    W  Write
                             Note: If a ; is present, this will be considered
                             a Perm;Spec parameter pair.

                       Perm: Is for "Files Only" and can be:
                             Permissions...
                                    F  Full control
                                    M  Modify
                                    X  read and eXecute
                                    R  Read
                                    W  Write
                             Advanced...
                                    D  Take Ownership
                                    C  Change Permissions
                                    B  Read Permissions
                                    A  Delete
                                    9  Write Attributes
                                    8  Read Attributes
                                    7  Delete Subfolders and Files
                                    6  Traverse Folder / Execute File
                                    5  Write Extended Attributes
                                    4  Read Extended Attributes
                                    3  Create Folders / Append Data
                                    2  Create Files / Write Data
                                    1  List Folder / Read Data
                       Spec is for "Folder and Subfolders only" and has the
                       same choices as Perm.

作者: XZ     时间: 2008-5-31 00:27
因為XCACLA.VBS無法像CACLS相同一次勾選預設部分 我將 "tao0610" 的程序加上了 if %1==R Set %%1=XLR if %1==W Set %%1=MXLRW 希望能讓R和W能像CACLS一樣勾起預設的選項 但是依然無法置換掉 %1的值 請求各為協助 謝謝 :lp1 set name=%1&shift :lp if not "%flag%"=="" ( echo %name% !Group%num%! %1 if %1==R Set %%1=XLR if %1==W Set %%1=MXLRW call cscript xcacls.vbs "%name%" /P "!Group%num%!":%1; /e ) else set Group%num%=%1 shift if not "%1"=="" set/a num+=1&goto lp