VBS Avancé // Récupérer la liste des groupes de sécurité

VBS Avancé // Récupérer la liste des groupes de sécurité - VB/VBA/VBS - Programmation

Marsh Posté le 06-08-2010 à 17:33:46    

Bonjour,
Je suis entrain de développer une application pour l'attribution des accès à des ressources partagées dans un réseau d'entreprise et je rencontre des difficultés en ce moment, car il faut à un moment donné que l'application récupère les groupes de sécurité (GG et GL) des sous répértoires de la ressource partagée en utilisant un script VBS, C.A.D les groupes de l'onglet sécurité quand on fait un clique droit ==> propriété.
 
Quelqu'un peut m'aider SVP pour la réalisation du script VBS
 
je vous remercie par avance


Message édité par mouataz le 06-08-2010 à 18:56:48
Reply

Marsh Posté le 06-08-2010 à 17:33:46   

Reply

Marsh Posté le 11-08-2010 à 00:14:58    

un premier pas vers une solution, un script que j'ai trouvé sur Microsoft Technet, ce code fonctionne dans une machine locale.
 

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


Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed