Below is a simple but useful VBScript that can be used to list windows shares and their permission. I create this for my wintel admin for audit purpose sometimes ago and has been tested to be workable on XP and WIN2K3/2K3...;-p
Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colItems : Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalShareSecuritySetting")
Dim objItem, intRtn, wmiSecurityDescriptor
Dim colDACLs, objACE, objUserGroup, strPermission, colShr, objShr, output ,arg
Function Folderpermission(strRunCmd)
'Wscript.Echo strRunCmd
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strRunCmd)
strOut = "Folder permission:"& vbCr & vbLf
Do While Not objExec.StdOut.AtEndOfStream
strOut = strOut & vbCr & vbLf & objExec.StdOut.ReadLine()
Loop
Set objShell = Nothing
Set objExec = Nothing
Folderpermission= strOut
End Function
Set wshShell = CreateObject( "WScript.Shell" )
strRegValue = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname"
strHostName = wshShell.RegRead( strRegValue )
WScript.Echo "Host Name: " & strHostName & vbCr & vbLf
Wscript.Echo "============================================================="
For Each objItem In colItems
WScript.Echo "Share Name: " & objItem.Name
Set colShr = objWMIService.ExecQuery("Select * from win32_share where name='" & objItem.Name & "'")
For Each objShr in colShr
WScript.Echo "Share Path: " & objShr.Path
' arg = "cacls " & """ & objShr.Path & """
arg = "cacls " & chr(34) & objShr.Path & chr(34)
Next
intRtn = objItem.GetSecurityDescriptor(wmiSecurityDescriptor)
colDACLs = wmiSecurityDescriptor.DACL
For Each objACE In colDACLs
Set objUserGroup = objACE.Trustee
WScript.Echo vbTab & "User/Group that has access: " & UCase(objUserGroup.Name)
Select Case objACE.AccessMask
Case 1179817 strPermission = "READ"
Case 1245631 strPermission = "CHANGE"
Case 2032127 strPermission = "FULL CONTROL"
End Select
WScript.Echo vbTab & "Permission: " & strPermission & VbCrLf
Next
Wscript.Echo (Folderpermission (arg))
Wscript.Echo "============================================================="
Next
Output of the script looks like this:
Host Name: Test-PC
=============================================================
Share Name: avaloq
Share Path: D:\test\avaloq
User/Group that has access: EVERYONE
Permission: FULL CONTROL
Folder permission:
D:\test\avaloq DomainA\kokei :(OI)(CI)F
=============================================================
Share Name: test
Share Path: D:\test
User/Group that has access: kokei
Permission: READ
Folder permission:
D:\test BUILTIN\Administrators:(OI)(CI)F
NT AUTHORITY\SYSTEM:(OI)(CI)F
DomainA\kokei:F
CREATOR OWNER:(OI)(CI)(IO)F
BUILTIN\Users:(OI)(CI)R
BUILTIN\Users:(CI)(special access:)
FILE_APPEND_DATA
BUILTIN\Users:(CI)(special access:)
FILE_WRITE_DATA
=============================================================
Share Name: shares
Share Path: D:\shares
User/Group that has access: EVERYONE
Permission: READ
User/Group that has access: kokei
Permission: FULL CONTROL
Folder permission:
D:\shares DomainA\kokei:(OI)(CI)F
BUILTIN\Administrators:(OI)(CI)F
NT AUTHORITY\SYSTEM:(OI)(CI)F
DomainA\kokei:F
CREATOR OWNER:(OI)(CI)(IO)F
BUILTIN\Users:(OI)(CI)R
BUILTIN\Users:(CI)(special access:)
FILE_APPEND_DATA
BUILTIN\Users:(CI)(special access:)
FILE_WRITE_DATA
=============================================================
Filed under:
Windows