Listage Répertoire + Droits

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

ThESeRvEuR

XLDnaute Nouveau
Bonjour à tous,

J'ai parcouru le forum en long en large et en travers mais je ne trouve rien.
J'ai trouvé énormément de Macro permettant le listage des répertoires, des sous-répertoires, et des fichiers mais malheureusement aucun d'entre eux ne propose de lister les droits d'un répertoire, d'un fichier, ...

Je ne sais pas si cela est possible mais vu le nombre de choses possible que j'ai pu découvrir au travers de mes recherches qu'il est possible de réaliser avec Excel, je me dis pourquoi pas.

Je n'ai pas de connaissance poussée dans la macro excel c'est pour cela que je viens vous demander de l'aide.

D'avance merci 🙂
 
Re : Listage Répertoire + Droits

@Pierrot93 :
Merci pour ta réponse, rapide en plus ... Mais je dirais : Mais bien sûre 😉 Pourquoi n'y ai-je pas pensé avant 😛 ... Je ne comprends même pas ce que tu me dis : "regarde du coté de "FileSystemObject", la propriété "Attributes" de l'objet "File"... " ... Et la marmotte elle est met le chocolat dans le papier d'alu 😛

@JCGL :

J'ai testé ton fichier, merci aussi pour ta réponse.
Problème, il ne liste que les fichiers d'un répertoire, pas les sous-répertoires. et ne sort que l'attribut du fichier

/Archive
/Caché/Système/Archive
/Caché/Archive
 
Re : Listage Répertoire + Droits

Je parle en fait des répertoires qui sont créés sur un serveur, partagés, et donc des utilisateurs autorisés à accéder aux répertoires avec oui ou non des droits de "contrôle total", droits de "modification", "lecture", "écriture", ...
De tout ce qu'il y a dans l'onglet "Sécurité" lorsque tu rentre dans les propriétés d'un répertoire sur un serveur.

Tu vois ce que je veux dire ?
 
Dernière édition:
Re : Listage Répertoire + Droits

Bonjour,
Re Pierrot🙂
Mon JC🙂

Je vais faire comme Pierrot et en rajouter une couche, il faut voir soit du côté des apis windows:
GetFileSecurity
GetSecurityDescriptorOwner
LookupAccountSid
And so...

Ou du côté de WMI s'il y fait beau. C'est par ICI

Rien que pour avoir le nom du propriétaire de nodepad.exe par les APIs:

Source: Comment faire pour obtenir le propriétaire d'un fichier sous Windows NT

VB:
Option Explicit
 
Private Declare Function GetFileSecurity Lib "advapi32.dll" _
                                         Alias "GetFileSecurityA" ( _
                                         ByVal lpFileName As String, _
                                         ByVal RequestedInformation As Long, _
                                         pSecurityDescriptor As Byte, _
                                         ByVal nLength As Long, _
                                         lpnLengthNeeded As Long _
                                       ) As Long
Private Declare Function GetSecurityDescriptorOwner Lib "advapi32.dll" _
                                                    (pSecurityDescriptor As Any, _
                                                     pOwner As Long, _
                                                     lpbOwnerDefaulted As Long) As Long
Private Declare Function LookupAccountSid Lib "advapi32.dll" _
                                          Alias "LookupAccountSidA" ( _
                                          ByVal lpSystemName As String, _
                                          ByVal sid As Long, _
                                          ByVal name As String, _
                                          cbName As Long, _
                                          ByVal ReferencedDomainName As String, _
                                          cbReferencedDomainName As Long, _
                                          peUse As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" _
                                             Alias "GetWindowsDirectoryA" ( _
                                             ByVal lpBuffer As String, _
                                             ByVal nSize As Long) As Long
Private Const OWNER_SECURITY_INFORMATION = &H1
Private Const ERROR_INSUFFICIENT_BUFFER = 122&
Private Const MAX_PATH = 255
 
Sub Command1_Click()
    Dim szfilename As String   ' File name to retrieve the owner for
    Dim bSuccess As Long       ' Status variable
    Dim sizeSD As Long         ' Buffer size to store Owner's SID
    Dim pOwner As Long         ' Pointer to the Owner's SID
    Dim name As String         ' Name of the file owner
    Dim domain_name As String  ' Name of the first domain for the owner
    Dim name_len As Long       ' Required length for the owner name
    Dim domain_len As Long     ' Required length for the domain name
    Dim sdBuf() As Byte        ' Buffer for Security Descriptor
    Dim nLength As Long        ' Length of the Windows Directory
    Dim deUse As Long          ' Pointer to a SID_NAME_USE enumerated
' type indicating the type of the account
' Initialize some required variables.
    bSuccess = 0
    name = ""
    domain_name = ""
    name_len = 0
    domain_len = 0
    pOwner = 0
    szfilename = Space(MAX_PATH)
    ' Obtain the path to the Windows Directory and use the notepad.exe file
    ' as it should be on the system.
    nLength = GetWindowsDirectory(szfilename, Len(szfilename))
    If nLength = 0 Then
        MsgBox "Unable to Obtain the Windows Directory"
    End If
    szfilename = Left$(szfilename, nLength) & "\notepad.exe"
    ' Call GetFileSecurity the first time to obtain the size of the
    ' buffer required for the Security Descriptor.
    bSuccess = GetFileSecurity( _
               szfilename, _
               OWNER_SECURITY_INFORMATION, _
               0, _
               0&, _
               sizeSD)
    If (bSuccess = 0) And _
       (Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER) Then
        MsgBox "GetLastError returned  : " & Err.LastDllError
    End If
    ' Create a buffer of the required size and call GetFileSecurity again.
    ReDim sdBuf(0 To sizeSD - 1) As Byte
    ' Fill the buffer with the security descriptor of the object specified
    ' by the szfilename parameter. The calling process must have the right
    ' to view the specified aspects of the object's security status.
    bSuccess = GetFileSecurity( _
               szfilename, _
               OWNER_SECURITY_INFORMATION, _
               sdBuf(0), _
               sizeSD, _
               sizeSD)
    If (bSuccess <> 0) Then
        ' Obtain the owner's SID from the Security Descriptor.
        '
        bSuccess = GetSecurityDescriptorOwner(sdBuf(0), pOwner, 0&)
        If (bSuccess = 0) Then
            MsgBox "GetLastError returned : " & Err.LastDllError
        End If
        ' Retrieve the name of the account and the name of the first
        ' domain on which this SID is found.  Passes in the Owner's SID
        ' obtained previously.  Call LookupAccountSid twice, the first time
        ' to obtain the required size of the owner and domain names.
        bSuccess = LookupAccountSid(vbNullString, pOwner, name, name_len, _
                                    domain_name, domain_len, deUse)
        If (bSuccess = 0) And _
           (Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER) Then
            MsgBox "GetLastError returned : " & Err.LastDllError
        End If
        '  Allocate the required space in the name and domain_name string
        '  variables. Allocate 1 byte less to avoid the appended NULL character.
        '
        name = Space(name_len - 1)
        domain_name = Space(domain_len - 1)
        '  Call LookupAccountSid again to actually fill in the name of the owner
        '  and the first domain.
        '
        bSuccess = LookupAccountSid(vbNullString, pOwner, name, name_len, _
                                    domain_name, domain_len, deUse)
        If bSuccess = 0 Then
            MsgBox "GetLastError returned : " & Err.LastDllError
        End If
        MsgBox "The Owner of " & szfilename & " is " & name
    End If
End Sub

A la votre!🙂🙂🙂

A+ à tous
 
Dernière modification par un modérateur:
Re : Listage Répertoire + Droits

Bonjour à tous,

Je connais que ces attributs :
  1. Nom
  2. Taille
  3. Type
  4. Date de modification
  5. Date de création
  6. Date d'accès
  7. Attributs
  8. État
  9. Propriétaire
  10. Auteur
  11. Titre
  12. Objet
  13. Catégorie
  14. Pages
  15. Commentaires
  16. Copyright
  17. Artiste
  18. Titre de l'album
  19. Année
  20. Numéro de piste
  21. Genre
  22. Durée
  23. Débit
  24. Protégée
  25. Modèle d'appareil photo
  26. Date du cliché
  27. Dimensions
  28. Nom de l'épisode
  29. Description du programme
  30. Taille de l'échantillon audio
  31. Taux d'échantillonnage audio
  32. Chaînes
A+ à tous
 
Re : Listage Répertoire + Droits

Re tous,

Je voulais montrer à TheServer la complexité, dès qu'on s'attache aux droits et strategies windows. Et que cela dépasse amplement le cadre d'un simple script VBA, même si dans l'absolu c'est tout à fait possible, encore faut-il qu'il ait lui même les droits 'Administrateur'.

A+ à tous.

[Edit]P.S. c'est pas parce que je connais cela que je le maîtrise forcément.
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 problème d'index
Réponses
19
Affichages
237
  • Question Question
Microsoft 365 Power Query
Réponses
8
Affichages
306
Réponses
4
Affichages
412
Réponses
32
Affichages
1 K
Retour