Advertisement

08.27.2008 at 01:57AM PDT, ID: 23681306 | Points: 500
[x]
Attachment Details

VB to display folder permissions

Asked by jamiepryer in VB Script

Tags:

Hi,
Im trying to find some code, that will display the permissions of a selected folder (under the security tab)
simple as that!

I found the below on the net, but this keeps falling over very early, as i dont have admin rights on the server.
http://www.clubusenet.com/thread/578869.htmlStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
Sub Main()
Dim filename_var As String
 
Dim strRemoteServerName As String
Dim strRemoteShareName As String
Dim strDefaultDomain As String
Dim strSystemDomainName As String
Dim strSystemDomainSid As String
 
Dim actualDirPath As String
Dim displayDirPath As String
Dim initialfilenameAbsPath As String
 
Dim fso As Scripting.FileSystemObject
 
Dim objLocator As WbemScripting.SWbemLocator
Dim objService As WbemScripting.SWbemServices
Dim objFileShare As WbemScripting.SWbemObject
 
Dim objFileSecSetting As WbemScripting.SWbemObject
Dim objSecDescriptor As Variant
Dim objOutParams As WbemScripting.SWbemObject
Dim objDACL_Member As Variant
Dim objtrustee As Variant
 
On Error GoTo OOPS
 
filename_var = "\\MYSERVER\myShareFolder"
 
'----------------------------------------
'set main variables
'----------------------------------------
GetServerNameString filename_var, strRemoteServerName,
strRemoteShareName
 
Set fso = New Scripting.FileSystemObject
 
Set objLocator = New WbemScripting.SWbemLocator
Set objService = objLocator.ConnectServer(strRemoteServerName,
"root/cimv2")
objService.Security_.ImpersonationLevel =
wbemImpersonationLevelImpersonate
objService.Security_.Privileges.AddAsString "SeSecurityPrivilege", True
 
Set objFileShare = objService.Get("Win32_Share.Name=""" &
strRemoteShareName & """")
actualDirPath = objFileShare.Path
displayDirPath = "\\" & strRemoteServerName & "\" & strRemoteShareName
 
initialfilenameAbsPath = fso.GetAbsolutePathName(Replace(filename_var,
displayDirPath, actualDirPath, 1, 1, 1))
 
'----------------------------------------
'check trustee
'----------------------------------------
GetDefaultNames objService, strDefaultDomain, strSystemDomainName
GetDefaultDomainSid objService, strSystemDomainSid, strSystemDomainName
 
Set objFileSecSetting =
objService.Get("Win32_LogicalFileSecuritySetting.Path=""" &
Replace(initialfilenameAbsPath, "\", "\\") & """")
Set objOutParams =
objFileSecSetting.ExecMethod_("GetSecurityDescriptor")
Set objSecDescriptor = objOutParams.Descriptor
 
If IsArray(objSecDescriptor.DACL) Then
For Each objDACL_Member In objSecDescriptor.DACL
Set objtrustee = objDACL_Member.Trustee
Debug.Print objtrustee.Domain & "\" & objtrustee.Name
Next
Else
Debug.Print "No permission defined"
End If
 
Set objSecDescriptor = Nothing
Set objOutParams = Nothing
Set objFileSecSetting = Nothing
Set objFileShare = Nothing
Set objService = Nothing
Set objLocator = Nothing
Set fso = Nothing
Exit Sub
 
OOPS:
Debug.Print "Error: " & Err.Number
Debug.Print "Source: " & Err.Source
Debug.Print "Description: " & Err.Description
End Sub
 
Private Function GetServerNameString(ByVal strFilePath As String, ByRef
strServerName As String, ByRef strShareName As String) As Boolean
Dim timeStart As Date
Dim timeEnd As Date
 
Dim strTempServer As String
Dim intShareStart As Long
Dim intShareEnd As Long
On Error Resume Next
GetServerNameString = False
If strFilePath = "" Then Exit Function
If Left(strFilePath, 2) <> "\\" Then Exit Function
If Len(strFilePath) < 3 Then Exit Function
strTempServer = Mid(strFilePath, 3)
intShareStart = InStr(1, strTempServer, "\", 1)
If intShareStart > 0 Then
strServerName = Left(strTempServer, intShareStart - 1)
strShareName = Mid(strTempServer, intShareStart + 1)
intShareEnd = InStr(1, strShareName, "\", 1)
If intShareEnd > 0 Then
strShareName = Left(strShareName, intShareEnd - 1)
End If
Else
strServerName = strTempServer
End If
GetServerNameString = True
End Function
 
Private Sub GetDefaultNames(ByRef objService As WbemScripting.SWbemServices,
ByRef strDefaultDomain As String, ByRef strSystemDomainName As String)
 
Const CONST_USE_LOCAL_FOR_NON_DCs = True
Dim objSystemSet As SWbemObjectSet
Dim objSystem As SWbemObject
Dim intRole As Long
On Error Resume Next
 
Set objSystemSet = objService.ExecQuery("SELECT Name, Domain, DomainRole
FROM Win32_ComputerSystem", , 0)
 
For Each objSystem In objSystemSet
If objSystem.Name <> "" Then
If objSystem.Domain <> "" Then
strSystemDomainName = objSystem.Domain
Else
strSystemDomainName = objSystem.Name
End If
intRole = objSystem.DomainRole
Select Case intRole
Case 0 'Standalone Workstation
strDefaultDomain = objSystem.Name
Case 1 'Member Workstation
If CONST_USE_LOCAL_FOR_NON_DCs Then
strDefaultDomain = objSystem.Name
Else
strDefaultDomain = objSystem.Domain
End If
Case 2 'Standalone Server
strDefaultDomain = objSystem.Name
Case 3 'Member Server
If CONST_USE_LOCAL_FOR_NON_DCs Then
strDefaultDomain = objSystem.Name
Else
strDefaultDomain = objSystem.Domain
End If
Case 4 'Backup Domain Controller
strDefaultDomain = objSystem.Domain
Case 5 'Primary Domain Controller
strDefaultDomain = objSystem.Domain
Case Else 'Don't know this one...so do nothing
strDefaultDomain = ""
End Select
Exit For
End If
Next
Set objSystem = Nothing
Set objSystemSet = Nothing
End Sub
 
Private Sub GetDefaultDomainSid(ByRef objService As
WbemScripting.SWbemServices, ByRef strSystemDomainSid As String, ByVal
strSystemDomainName As String)
Dim objSystemSet As SWbemObjectSet
Dim objSystem As SWbemObject
Dim strQuery As String
 
strSystemDomainSid = ""
strQuery = "SELECT Sid FROM Win32_Group WHERE Domain=""" &
strSystemDomainName & """ and Name=""Domain Admins"""
 
Set objSystemSet = objService.ExecQuery(strQuery, , 0)
 
For Each objSystem In objSystemSet
If objSystem.Sid <> "" Then
If Left(objSystem.Sid, 6) = "S-1-5-" And Right(objSystem.Sid, 4) =
"-512" Then
strSystemDomainSid = Mid(objSystem.Sid, 7)
strSystemDomainSid = Left(strSystemDomainSid,
Len(strSystemDomainSid) - 4)
Exit For
End If
End If
Next
 
Set objSystem = Nothing
Set objSystemSet = Nothing
End Sub
[+][-]08.27.2008 at 03:26AM PDT, ID: 22323056

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 03:35AM PDT, ID: 22323112

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 03:36AM PDT, ID: 22323120

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 04:09AM PDT, ID: 22323299

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 04:29AM PDT, ID: 22323413

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.27.2008 at 05:59PM PDT, ID: 22818331

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628