Hello folks,
When I needed to code some check on share permissions, I came across code below.
The problem I found is that when I try using variable in place of directory name (WMILogs$) - to make script check different shares - I get syntax errors.
Can you help me please.
On Error Resume Next
' The Win32_LogicalShareSecuritySetting instance with
' the name = to WMILogs$ is specified
Set wmiFileSecSetting = GetObject( _
"winmgmts:Win32_LogicalShareSecuritySetting.Name='WMILogs$'")
RetVal = wmiFileSecSetting. _
GetSecurityDescriptor(wmiSecurityDescriptor)
If Err <> 0 Then
WScript.Echo "GetSecurityDescriptor failed" _
& VBCRLF & Err.Number & VBCRLF & Err.Description
WScript.Quit
Else
WScript.Echo "GetSecurityDescriptor succeeded"
End If
' Retrieve the DACL array of Win32_ACE objects.
DACL = wmiSecurityDescriptor.DACL
For each wmiAce in DACL
wscript.echo "Access Mask: " & wmiAce.AccessMask
wscript.echo "ACE Type: " & wmiAce.AceType
' Get Win32_Trustee object from ACE
Set Trustee = wmiAce.Trustee
wscript.echo "Trustee Domain: " & Trustee.Domain
wscript.echo "Trustee Name: " & Trustee.Name
' Get SID as array from Trustee
SID = Trustee.SID
strsid = join(SID, ",")
wscript.echo "Trustee SID: {" & strsid & "}"
Next
When I needed to code some check on share permissions, I came across code below.
The problem I found is that when I try using variable in place of directory name (WMILogs$) - to make script check different shares - I get syntax errors.
Can you help me please.
On Error Resume Next
' The Win32_LogicalShareSecuritySetting instance with
' the name = to WMILogs$ is specified
Set wmiFileSecSetting = GetObject( _
"winmgmts:Win32_LogicalShareSecuritySetting.Name='WMILogs$'")
RetVal = wmiFileSecSetting. _
GetSecurityDescriptor(wmiSecurityDescriptor)
If Err <> 0 Then
WScript.Echo "GetSecurityDescriptor failed" _
& VBCRLF & Err.Number & VBCRLF & Err.Description
WScript.Quit
Else
WScript.Echo "GetSecurityDescriptor succeeded"
End If
' Retrieve the DACL array of Win32_ACE objects.
DACL = wmiSecurityDescriptor.DACL
For each wmiAce in DACL
wscript.echo "Access Mask: " & wmiAce.AccessMask
wscript.echo "ACE Type: " & wmiAce.AceType
' Get Win32_Trustee object from ACE
Set Trustee = wmiAce.Trustee
wscript.echo "Trustee Domain: " & Trustee.Domain
wscript.echo "Trustee Name: " & Trustee.Name
' Get SID as array from Trustee
SID = Trustee.SID
strsid = join(SID, ",")
wscript.echo "Trustee SID: {" & strsid & "}"
Next