Click to See Complete Forum and Search --> : Retrieving remote share permissions - VB.net 2010


gregm
May 7th, 2010, 04:02 PM
I've search tons of .net pages and all I can seem to find is vbs code for retrieving remote share permissions using WMI.

I've tried to convert this code to run on vb.net but don't seem to be getting anywhere.

Can anyone help - should I try to convert the below code or are there other methods I can use to retrieve the permissions. I can easily get the list of remote shares using win32_share but not the permissions :(


strComputer = WScript.Arguments(0)

Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMI.ExecQuery("Select * from win32_share")

For Each i In colItems

strDir = i.path
WScript.Echo "Share Name: " & i.name

strDir = Replace(strDir,"\","\\")
Set colItems = objWMI.ExecQuery("Select * from win32_logicalFileSecuritySetting WHERE Path='" & strDir & "'",,48)

for each objItem in colItems

If objItem.GetSecurityDescriptor(wmiSecurityDescriptor) Then
WScript.Echo "GetSecurityDescriptor failed"
DisplayFileSecurity = False
WScript.Quit
End If

For each wmiAce in wmiSecurityDescriptor.DACL
strACE = wmiAce.Trustee.Domain & "\" & wmiAce.Trustee.Name
'If instr(strACE,".") then
wscript.echo " " & strACE
'end If
Next
Next
Next

dglienna
May 7th, 2010, 06:07 PM
Something like this:

'Correct the security for the share on NTFS-permission
Set objShell = CreateObject("Wscript.Shell")
objShell.run("cmd /c echo y| cacls " & path & sharename & " /t /g " & DLG_RWXD &_
":C " & DLG_RX & ":R "& """domain admins""" & ":F")



ADScriptoMatic

http://gallery.technet.microsoft.com/ScriptCenter/en-us/1648b0cb-129b-45df-964f-f160a6481767