
Share and NTFS Permissions
I am trying to write a script to find out which rights users and groups have
on a networkshare. And I want to know this on share level and NTFS level. I
wrote a script that does something like this, but it gives back only the
rights of one user/group which is not identified and it are only the rights
for the share. I can find lots of things about how to set permissions, but
nothing about reading the permissions. Can someone help me or point me in
the right direction?
This is the code I have made (pretty simple though):
On Error Resume Next
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("Permissions.txt", True)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Share",,48)
For Each objItem in colItems
ObjTextFile.WriteLine "Path: " & objItem.Path
ObjTextFile.WriteLine "Permissions:"
calculate(objItem.GetAccessMask)
next
sub calculate(iPerm)
if iPerm >= 1048576 then
ObjTextFile.WriteLine vbtab & "SYNCHRONIZE"
calculate(iPerm - 1048576)
elseif iPerm >= 524288 then
ObjTextFile.WriteLine vbtab & "WRITE_OWNER"
calculate(iPerm - 524288)
elseif iPerm >= 262144 then
ObjTextFile.WriteLine vbtab & "WRITE_DAC"
calculate(iPerm - 262144)
elseif iPerm >= 131072 then
ObjTextFile.WriteLine vbtab & "READ_CONTROL"
calculate(iPerm - 131072)
elseif iPerm >= 65536 then
ObjTextFile.WriteLine vbtab & "DELETE"
calculate(iPerm - 65536)
elseif iPerm >= 256 then
ObjTextFile.WriteLine vbtab & "FILE_WRITE_ATTRIBUTES"
calculate(iPerm - 256)
elseif iPerm >= 128 then
ObjTextFile.WriteLine vbtab & "FILE_READ_ATTRIBUTES"
calculate(iPerm - 128)
elseif iPerm >= 64 then
ObjTextFile.WriteLine vbtab & "FILE_DELETE_CHILD"
calculate(iPerm - 64)
elseif iPerm >= 32 then
ObjTextFile.WriteLine vbtab & "FILE_TRAVERSE"
calculate(iPerm - 32)
elseif iPerm >= 16 then
ObjTextFile.WriteLine vbtab & "FILE_WRITE_EA"
calculate(iPerm - 16)
elseif iPerm >= 8 then
ObjTextFile.WriteLine vbtab & "FILE_READ_EA"
calculate(iPerm - 8)
elseif iPerm >= 4 then
ObjTextFile.WriteLine vbtab & "FILE_ADD_SUBDIRECTORY"
calculate(iPerm - 4)
elseif iPerm >= 2 then
ObjTextFile.WriteLine vbtab & "FILE_ADD_FILE"
calculate(iPerm - 2)
elseif iPerm >= 1 then
ObjTextFile.WriteLine vbtab & "FILE_LIST_DIRECTORY"
calculate(iPerm - 1)
end if
end sub