VBScript 递归 ACL 列表






4.33/5 (5投票s)
2005年9月20日

138116
列出目录及其子目录的访问控制列表。
快速简便的 ACL 打印
这是一个 VBScript,它将列出您指定的目录中所有子目录的 ACL。 许多企业希望保留安全设置的纸质记录以用于灾难恢复,但 Windows 中没有内置工具可以一次打印多个目录的 ACL,而像“pracl”这样的替代方案也相当昂贵。
对于任何不是最简单的目录结构,手动打印它们都非常麻烦,所以我采用了“VBScript 目录爬虫”并对其进行了修改,以启动 cacls 来显示目录及其所有子目录的 ACL 信息。
显然,要将此输出放入文件,只需执行“cscript listacl.vbs > acl.txt
”。
代码
' ListACL.vbs
' ACL Modifications by CyberneticWraith, 2005
' Changed it to display ACL information for folders
' Uses "cacls.exe"
' Run with cscript!
'
'
' IndexScripts()
'
'
' Written by Keep Bertha Surfin Heavy Industries,
' a division of Keep Bertha Surfin Electrical Concern
' Version 1.0 - KeepBerthaSurfin@Hotmail.com
'
' First thing, check the argument list for a directory.
' If they didn't specify one, use the current directory.
option explicit
' Run the function :)
call IndexScripts
sub IndexScripts()
dim fso
set fso = createobject("scripting.filesystemobject")
dim loc
if WScript.Arguments.Count = 0 then
loc = fso.GetAbsolutePathName(".")
else
loc = WScript.Arguments(0)
end if
GetWorkingFolder loc, 0, 1, "|"
set fso = nothing
End Sub
' called recursively to get a folder to work in
function GetWorkingFolder(foldspec, foldcount, _
firsttime, spacer)
Dim objShell,oExec
Set objShell = CreateObject("WScript.Shell")
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim fold
set fold = fso.GetFolder(foldspec)
dim foldcol
set foldcol = fold.SubFolders
'do the first folder stuff
if firsttime = 1 then
wscript.echo fold.path
foldcount = foldcol.count
firsttime = 0
end if
dim remaincount
remaincount = foldcol.count
'do the subfolder stuff
dim sf
for each sf in foldcol
'execute cacls to display ACL information
Set oExec = _
objShell.Exec("cacls " & chr(34) & sf.path & chr(34))
Do While Not oExec.StdOut.AtEndOfStream
str = oExec.StdOut.ReadAll
Dim str
Wscript.StdOut.WriteLine str
Loop
set oExec = nothing
remaincount = GetWorkingFolder (foldspec +"\"+sf.name, _
remaincount, firsttime, spacer)
next
'clean up
set fso = nothing
GetWorkingFolder = foldcount - 1
end function