IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Afficher les droits NTFS d'un répertoire


Sujet :

VBScript

  1. #1
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut Afficher les droits NTFS d'un répertoire
    Bonjour,

    Je cherche un script permettant d'afficher les droits NTFS d'un répertoire. J'ai trouvé des script pour modifier/ajouter, mais pas pour lire...

    Auriez-vous cela en stock ?

    J'ai regardé un peu du côté de la commande "Cacls". Cela m'affiche :

    c:\Windows NT SERVICE\TrustedInstaller:F
    NT SERVICE\TrustedInstaller:(CI)(IO)F
    AUTORITE NT\Système:C
    AUTORITE NT\Système:(OI)(CI)(IO)F
    BUILTIN\Administrateurs:C
    BUILTIN\Administrateurs:(OI)(CI)(IO)F
    BUILTIN\Utilisateurs:R
    BUILTIN\Utilisateurs:(OI)(CI)(IO)(accès spécial*:)
    GENERIC_READ
    GENERIC_EXECUTE

    CREATEUR PROPRIETAIRE:(OI)(CI)(IO)F
    J'aurai voulu avoir quelque chose comme ça (pour que cela soit utilisable dans un tableau Excel)

    c:\Windows;BUILTIN\Administrateurs:(OI)(CI)(IO)F
    c:\Windows;BUILTIN\Utilisateurs:R
    ......
    Et me dire si le droit est un droit hérité ou pas. On a l'information via (OI). Plus simple à comprendre.

    Merci d'avance,
    Arnaud

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut List Subfolder Access Permissions

  3. #3
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Salut,

    Je n'avais pas trouvé ce script sur le MSDN.

    J'ai regardé rapidement, tu peux me dire si ce script est capable de paresser récursivement tout un répertoire (comme le fait ton script sur le post où on a conversé précédemment) ?

    J'ai ma réponse : oui

    Le hic, c'est qu'il m'affiche des groupes de sécurité lier à un répertoire, mais pas les accès (lecture, écriture)...

    Et pour certains répertoires, les groupes affichés sont faux :

    Nom : 25i84xz.jpg
Affichages : 1435
Taille : 253,4 Ko

  4. #4
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    J'ai trouvé ce script qui me semble pas mal :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    '========================================================================== 
    ' 
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0 
    ' 
    ' NAME: Folder Permission  
    ' 
    ' AUTHOR:  Abdelkader, Amine 
    ' DATE  : 10/03/2006 
    ' 
    ' COMMENT: Create a file with the name of the folder in HTML format  
    ' 
    '========================================================================== 
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
     
    Const FullAccessMask = 2032127, ModifyAccessMask = 1245631, WriteAccessMask = 118009 
    Const ROAccessMask = 1179817 
     
     
     
    strComputer = "." 
    sParentFolder = InputBox("Please Enter folder to gather information on", "Parent Folder") 
    SParentFoldern=replace(sParentFolder,"\","") 
    SParentFoldern=replace(sParentFoldern,":","") 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    'File name Same As Folder Name without special Caracteres  
    fullfilename=SParentFoldern&".html" 
    'WScript.echo fullfilename 
     
    Set fsOut = fso.OpenTextFile(fullfilename, ForAppending, True) 
     
    On Error Resume Next 
     
    fsOut.Writeline ("<html>"&vbCr&"<head>"&vbCr&"<title>File Permission For Folder under &"& SParentFoldern&"</title>"&vbCr&"</head>") 
     
    strTableHead = "<table border=2 bordercolor='#000010' width='90%' id='Table1'>" 
    fsOut.Writeline strTableHead 
    fsOut.Writeline "<tr><td width='50%'>Folder</td>" & _ 
                    "<td width='50%'>User Name</td>"&_ 
                    "<td width='50%'>Permission</td></tr>" 
     
    strTableFoot = "</table>" 
     
    fsOut.Close 
     
     
     
    ShowSubFolders FSO.GetFolder(sParentFolder),fullfilename 
     
    OutputFolderInfo sParentFolder, fullfilename 
     
    Set fsOut = fso.OpenTextFile(fullfilename, ForAppending, True) 
    fsOut.Writeline strTableFoot  
    fsOut.Close 
    MsgBox "Done " 
    WScript.Quit 
     
    Public Sub OutputFolderInfo(FolderName , sOutfile) 
     
    Const FullAccessMask = 2032127, ModifyAccessMask = 1245631, WriteAccessMask = 1180095 
    Const ROAccessMask = 1179817 
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
     
    strComputer = "." 
     
    'Build the path to the folder because it requites 2 backslashes 
    folderpath = Replace(FolderName, "\", "\\") 
     
    objectpath = "winmgmts:Win32_LogicalFileSecuritySetting.path='" & folderpath & "'" 
     
    'Get the security set for the object 
    Set wmiFileSecSetting = GetObject(objectpath) 
     
    'verify that the get was successful 
    RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor) 
     If Err Then 
         MsgBox ("GetSecurityDescriptor failed" & vbCrLf & Err.Number & vbCrLf & Err.Description) 
         Err.Clear 
     End If 
     
     
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _ 
        strComputer & "\root\cimv2") 
    Set colFolders = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name ='" & _ 
        folderpath & "'") 
    For Each objFolder In colFolders 
     
        ' Retrieve the DACL array of Win32_ACE objects. 
        DACL = wmiSecurityDescriptor.DACL 
     
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set fsOut = fso.OpenTextFile(sOutfile, ForAppending, True) 
     
     
        For Each wmiAce In DACL 
        ' Get Win32_Trustee object from ACE 
            Set Trustee = wmiAce.Trustee 
            fsOut.Writeline "<tr><td width='50%'>"&objFolder.Name&"</td>" & _ 
                    "<td width='50%'>"&Trustee.Domain&"\"&Trustee.Name&"</td>" 
     
            'fsOut.Write objFolder.Name & "," & Trustee.Domain & "\" & Trustee.Name & "," 
            FoundAccessMask = False 
            CustomAccessMask = Flase 
            While Not FoundAccessMask And Not CustomAccessMask 
                If wmiAce.AccessMask = FullAccessMask Then 
                    AccessType = "Full Control" 
                    FoundAccessMask = True 
                End If 
                If wmiAce.AccessMask = ModifyAccessMask Then 
                    AccessType = "Modify" 
                    FoundAccessMask = True 
                End If 
                If wmiAce.AccessMask = WriteAccessMask Then 
                    AccessType = "Read/Write Control" 
                    FoundAccessMask = True 
                End If 
                If wmiAce.AccessMask = ROAccessMask Then 
                    AccessType = "Read Only" 
                    FoundAccessMask = True 
                Else 
                    CustomAccessMask = True 
                End If 
            Wend 
     
            If FoundAccessMask Then 
                'fsOut.Writeline AccessType 
                fsOut.Writeline "<td width='50%'>"&AccessType&"</td></tr>" 
            Else 
                 fsOut.Writeline "<td width='50%'>Custom</td></tr>" 
                'fsOut.Writeline "Custom" 
            End If 
     
        Next 
     
        Set fsOut = Nothing 
        Set fso = Nothing 
     
    Next 
     
    Set fsOut = Nothing 
    Set fso = Nothing 
     
    end Sub 
    Sub ShowSubFolders (Folder,fname) 
    On Error Resume Next  
        For Each Subfolder in Folder.SubFolders 
            Call OutputFolderInfo(Subfolder.Path,fname) 
            Wscript.Echo Subfolder.Path 
            call ShowSubFolders (Subfolder,fname) 
        Next 
    End Sub
    Mais, je n'ai pas l'information pour savoir si le droit d'accès est un héritage ou pas.

    J'ai remarqué que les droit d'accès qui sont en doublon sont des droits hérité.

    J'aurai bien aimé avoir cette information de façon fiable dans le script... Je ne sais comment faire.

  5. #5
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    Voici ce que j'ai pu faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    Option Explicit
    Dim Title,Copyright,objShell,objFolder,CheminDossier,NomDossier,NomFichier,oFSO,Dossier,Folder,Fichier
    Title = "Lister les Droits sur les fichiers et les dossiers"
    Copyright = " © Hackoo 2014"
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(0,Title & Copyright,1,"c:\Programs")
    If objFolder Is Nothing Then
        WScript.Quit
    End If
    CheminDossier = objFolder.self.path
    NomDossier = objFolder.Title
    NomFichier = NomDossier & ".csv"
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    If oFSO.FileExists(NomFichier) Then
        oFSO.DeleteFile(NomFichier)
    End If    
    Set Dossier = oFSO.GetFolder(CheminDossier)
     
    Call Lister_Droits(Dossier)
     
    For each Folder in  oFSO.GetFolder(Dossier).SubFolders
        Lister_Droits(Folder) 
    Next
     
    For each Fichier in  oFSO.GetFolder(Dossier).Files
        Lister_Droits(Fichier) 
    Next
     
    Call Afficher_Resultat()  
    '**************************************************************************************************************
    Function Lister_Droits(objet)
        Dim Ws,Command,Execution
        Set Ws = CreateObject("WScript.Shell")
        Command = "CMD /c cacls "& qq(objet) &" >> " & NomFichier & ""
        Execution = ws.Run(Command,0,True) 'exécution de la commande sans afficher la console MS-DOS
    End Function
    '**************************************************************************************************************
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    '**************************************************************************************************************
    Sub Afficher_Resultat()
        Dim Ws,Command2,Command3,Command4,Execution,Resultat,UnicodeFile,AsciiFile
        Set Ws = CreateObject("WScript.Shell")
        UnicodeFile = "UnicodeDroits_"& NomFichier
        AsciiFile = "Droits_"& NomFichier
        Command2 = "CMD /U /C Type " & NomFichier & " > " & UnicodeFile &""
        Command3 = "CMD /C Del " & NomFichier &"" 
        Command4 = "CMD /C Del " & UnicodeFile &""
        Execution = ws.Run(Command2,0,True)
        Execution = ws.Run(Command3,0,True)
        Call Convert(UnicodeFile,AsciiFile)
        Execution = ws.Run(Command4,0,True)
        Resultat = ws.Run(AsciiFile,1,True)
    End Sub
    '**************************************************************************************************************
    'Pour Convertir le LogFile de Unicode en Ascii
    Sub Convert(UnicodeFile,AsciiFile)
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        Const ModeAscii = 0, ModeUnicode = -1
        Dim fso, f_in, f_out
        Set fso = CreateObject("Scripting.FileSystemObject" )
        Set f_in = fso.OpenTextFile(UnicodeFile, ForReading,, ModeUnicode)
        Set f_out = fso.OpenTextFile(AsciiFile, ForWriting, true, ModeAscii)
        Do Until f_in.AtEndOfStream
            f_out.Write f_in.Read(1)
        Loop
        f_in.Close
        f_out.Close
    End Sub
    '**************************************************************************************************************

  6. #6
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Merci beaucoup !

  7. #7
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    J'ai testé le script.

    Le problème est que je ne peux l'exploiter dans un Excel et faire des filtres car ce n'est pas un vrais fichier CSV qui est généré.

    L'idéal serai d'avoir en résultat quelque chose de ce genre :

    Fullname;Identity;Rights;IsInherited
    D:\Bureau\xxx\Original;NT SERVICE\WMPNetworkSvc;read/write;Flase
    D:\Bureau\xxx\Original;NT SERVICE\WMPNetworkSvc;read;True
    D:\Bureau\xxx\toto;BUILTIN\Administrateurs;FullControl;True
    Cela est-il réalisable ?

Discussions similaires

  1. [PHP 5.3] Lister les droits NTFS d'un répertoire
    Par General_Batton dans le forum Langage
    Réponses: 1
    Dernier message: 16/10/2014, 11h43
  2. Réponses: 8
    Dernier message: 01/12/2007, 23h52
  3. Récupérer les droits utilisateurs d'un répertoire
    Par orosseels dans le forum VBScript
    Réponses: 1
    Dernier message: 05/07/2007, 16h16
  4. Réponses: 6
    Dernier message: 29/05/2007, 13h33
  5. Réponses: 5
    Dernier message: 06/03/2003, 13h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo