| 12
 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
 
 | '================================================= 
'================================================= 
Dim Services,DescDeSec, ClasSec, PourQui
Dim ACE, InParam, Cher
Dim FSO, ObjShell
Dim CheminPartage, NomPartage, Description
 
CheminPartage = "D:\OrdisDom"    
NomPartage = "OrdisDom"
Description = "Pour Ordis du Dom."
 
' ================================== 
' Creer le Nouveau répertoire
' ==================================
Set FSO = CreateObject("Scripting.FileSystemObject")
If not FSO.FolderExists(CheminPartage) then
FSO.CreateFolfer(CheminPartage)
End If
Set FSO = Nothing
 
' ================================== 
' Objet 
' ==================================
' Strcomputer = "." si c'est l'ordinateur local ou vous pouvez mettre le nom de l'ordinateur en clair.
strComputer = "Nom de l'ordinateur"
 
Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
' ================================== 
' Prépare un Descripteur De Securité
' pour donner les droits d'accès au partage 
' ==================================
Set ClasSec = Services.Get("Win32_SecurityDescriptor")
Set DescDeSec = ClasSec.SpawnInstance_()
 
' Qui est concerné
Set PourQui = _
Services.Get("Win32_Trustee").SpawnInstance_
 
PourQui.Domain = Null
PourQui.Name = "TOUT LE MONDE"
PourQui.Properties_.Item("SID") = _
Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
 
Set ACE = Services.Get("Win32_Ace").SpawnInstance_
 
' Contrôle Total
ACE.Properties_.Item("AccessMask") = 2032127
 
' héritage aux objets et conteneurs
ACE.Properties_.Item("AceFlags") = 3
 
ACE.Properties_.Item("AceType") = 0
 
' Qui est concerné : Défini plus haut
ACE.Properties_.Item("Trustee") = PourQui
 
' puisque DACL est défini ...
DescDeSec.Properties_.Item("ControlFlags") = 4
 
' fin de la préparation du descripteur de sécurité
DescDeSec.Properties_.Item("DACL") = Array(ACE)
 
' ================================== 
' Création du Partage (enfin)
' ================================== 
Set Cher = Services.Get("Win32_Share")
 
Set InParam = _
Cher.Methods_("Create").InParameters.SpawnInstance_()
 
InParam.Properties_.Item("Access") = DescDeSec
InParam.Properties_.Item("Description") = Description
InParam.Properties_.Item("Name") = NomPartage
InParam.Properties_.Item("Path") = CheminPartage
 
' Type de partage : Répertoire ou fichier : 0 pour dossier
InParam.Properties_.Item("Type") = 0
 
' Nombre de Connexions simultanées permises sur le partage
InParam.Properties_.Item("MaximumAllowed") = 1
 
On error Resume next
Cher.ExecMethod_ "Create", InParam
 
If err<>0 then
   Msgbox "Echec de la création du partage"
End if
On error Goto 0
 
Set Services = Nothing
Set DescDeSec = Nothing
Set ClasSec = Nothing
Set PourQui = Nothing
Set ACE = Nothing
Set InParam = = Nothing
set Cher = Nothing
 
' ================================== 
' infos dans onglet Sécurité ...
' Permet de données les droits aux données du dossier
' ================================== 
Set ObjShell = WScript.CreateObject ("WSCript.shell")
 
Commande = "CACLS " & CheminPartage _
& " /E " _
& "/G ""Ordinateurs du domaine"":R"
 
Retour = objShell.Run( _
"%COMSPEC% /c Echo Y| " & Commande, 2, True)
 
If Retour <> 0 then
   Msgbox "Problème pour CACLS"
End if
 
Set ObjShell = Nothing | 
Partager