Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

winmgmts:Win32_LogicalShareSecuritySetting.Name : help with usage

Status
Not open for further replies.

ggolub

Programmer
Jan 5, 2005
13
US
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

 
I get syntax errors
Which line of code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here is what i run and get:

C:\vb1>cscript /nologo a1.vbs
GetSecurityDescriptor failed
424
Object required

C:\vb1>

------ a1.vbs

a("sc")

function a(f_name)
On Error Resume Next
' The Win32_LogicalShareSecuritySetting instance with
' the name = to WMILogs$ is specified

Set wmiFileSecSetting = GetObject( _
"winmgmts:Win32_LogicalShareSecuritySetting.Name='" & f_name & "'""")
' "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
end function
 
I'd replace this:
"winmgmts:Win32_LogicalShareSecuritySetting.Name='" & f_name & "'""")
with this:
"winmgmts:Win32_LogicalShareSecuritySetting.Name='" & f_name & "'")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top