on error resume next
ForAppending = 8
ResFIL = "Dossiers_Partages.csv"
set oFSO = CreateObject("Scripting.FileSystemObject")
set oFIL = oFSO.opentextfile(ResFIL, ForAppending, TRUE)
oFIL.write("NOM;CHEMIN;COMPTE_NT") & vbcrlf
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each oSHARE in colShares
'oFIL.write(oSHARE.caption & ";" & oSHARE.Name & ";" & oSHARE.Path & ";" & oSHARE.Type) & vbcrlf
'msgbox oSHARE.Name
if oSHARE.Type = 0 then
Set wmiFileSecSetting = GetObject( _
"winmgmts:Win32_LogicalShareSecuritySetting.Name='" & oSHARE.Name & "'")
if Err <>0 then
oFIL.write("@" & oSHARE.name & ";Echec analyse LogicalShare") & vbcrlf
err.clear
Else
RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)
If Err <> 0 Then
WScript.Echo "GetSecurityDescriptor failed" _
& VBCRLF & Err.Number & VBCRLF & Err.Description
WScript.Quit
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
'oFIL.write(oSHARE.caption & ";" & Trustee.Domain)
oFIL.write(oSHARE.Name & ";" & oSHARE.Path & ";" & Trustee.Name) & vbcrlf
' Get SID as array from Trustee
'SID = Trustee.SID
'strsid = join(SID, ",")
'wscript.echo "Trustee SID: {" & strsid & "}"
Next
End if
Set wmiFileSecSetting = nothing
End if
Next
oFIL.close
set oFIL = nothing
set oFSO = nothing
msgbox "Terminé !"
Partager