Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

cacls

4 réponses
Avatar
rénald
Hello,

Cela fait 24 heures que je me casse les dents sur un truc qui semble simple
en apparence.

j'essaye de lister les DACL du répertoire windows depuis un scipt VBS, mais
le problème c'est que wshshell.run n'a pas l'air de prendre les arguments,
en l'occurence le répertoire à checker et le fichier vers lequel stocker le
résultat.

j'essaye le scritp suivant :

directoire = "c:\windows >> c:\folder.html"
On Error Resume next

set wshshell =wscript.createobject("wscript.shell")
wshshell.run "cacls.exe" &directoire

MsgBox("finish")

une idée

merci

4 réponses

Avatar
Michel__D
Bonjour,

rénald a écrit :
Hello,

Cela fait 24 heures que je me casse les dents sur un truc qui semble simple
en apparence.

j'essaye de lister les DACL du répertoire windows depuis un scipt VBS, mais
le problème c'est que wshshell.run n'a pas l'air de prendre les arguments,
en l'occurence le répertoire à checker et le fichier vers lequel stocker le
résultat.

j'essaye le scritp suivant :

directoire = "c:windows >> c:folder.html"
On Error Resume next

set wshshell =wscript.createobject("wscript.shell")
wshshell.run "cacls.exe" &directoire

MsgBox("finish")

une idée

merci



Bon il y a déja un truc à comprendre ce n'est pas CACLS.EXE qui va rediriger
ta sortie mais la console soit CMD.EXE, donc essaye comme ceci :

..
wshshell.run "cmd /c cacls " & directoire
..

PS:Et attention au espace
Avatar
JF
*Bonjour rénald*


j'essaye de lister les DACL du répertoire windows



À tout hasard je signale ACCESSENUM
www.microsoft.com/france/technet/sysinternals/security/accessenum.mspx
http://technet.microsoft.com/fr-fr/sysinternals/bb897332.aspx
http://technet.microsoft.com/en-us/sysinternals/bb897332.aspx
http://download.sysinternals.com/Files/AccessEnum.zip

--
Salutations, Jean-François
Avatar
Lotre
Bonjour,

rénald wrote:
Hello,

Cela fait 24 heures que je me casse les dents
(...)
directoire = "c:windows >> c:folder.html"
(...)
wshshell.run "cacls.exe" &directoire




la redirection ne peut pas fonctionner ainsi ...
il faudrait utiliser cmd qui lancerait lui même cacls ET redirigerait
la sortie de cacls.

Par ailleurs, pourquoi ne pas utiliser xcacls.vbs avec les
commutateurs /L et /Q ?

XCACLS C:Windows /Q /L D:Tempdacl_windows.txt

....
ou alors ...
....

Voici un script que je me suis fait pour lire des autorisations et
organiser ça dans un csv...

Le ou les arguments peuvent être des dossiers ou des fichiers.

Au lancement, il est demander de faire des choix :
- analyse récursive ou non et si oui jusqu'où ?
- dossiers et/ou fichiers ?
- On peut même filtrer par extension ...

Attention, certaines lignes seront à vérifier car les logiciels de
courrier n'aiment pas les longues lignes ....
Comme le code est documenté, cela devrait être assez facile...

Tu peux aussi le modifier en passant directement après la récupération
des paramètres
(J'ai indiqué l'endroit par une double ligne de "#")
en remplissant convenablement les variables booléennes
ChoixExt, DOSSIERS et FICHIERS

et éventuellement TabExt et NbExt :
TabExt : tableau des extentions choisies
indices de 0 à NbExt ...

Cordialement,

HB.


' ############## Autorisations_cvs.vbs ##################
' =========== VARIABLES === ' Tableaux
Dim Code(16), Nom(16)
Dim CodeSt(6), NomSt(6)
Dim CodeG(5), NomG(5)
Dim TablExt(20)
' objets
Dim ONET, FSO, oIE, ts, FichierListe, fdo, ObjArgs
' chaînes
Dim Machine, Chemin, FicHtml, Titre
Dim CheminFichier, EXT, Bidon, Cc
' Valeurs numériques
Dim Nb, NbArgs, IArgs, NbExt, KOI, PROFONDEUR , Ii
' DWORD de la BdR
DIM AGARDER
' Booléens
Dim FICHIERS, DOSSIERS, ChoixExt
' ============ Récupération des arguments transmis ================ Set ObjArgs = WScript.Arguments
Nb = ObjArgs.Count

NbArgs = Nb - 1
' ================= ze fso ,bien sûr ============================== Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
' ============== remplissage des tableaux ======================== INIT()
' ====================nom de la machine =========================== set ONET = WScript.CreateObject("wscript.Network")
Machine = ONET.ComputerName
set ONET = Nothing

' ================== Chemin du script ============================= Chemin = WScript.ScriptFullName

' =========================================================== ' =============== page html pour les paramètres ============= ' =========================================================== Titre = "Liste des ACL : Paramétrage"
FicHtml=Left(Chemin, InStrRev(Chemin, "")) & "index.html"
Set ts = FSO.CreateTextFile(FicHtml, True)
' =========================================================== ts.writeline "<html>"
ts.writeline "<head>"
ts.writeline "<title>" & Titre & "</title>"
ts.writeline "<STYLE TYPE=""text/css"">"
ts.writeline " body {"
ts.writeline " font-family: Verdana;"
ts.writeline " font-size: 10 pt }"
ts.writeline " h1, h2, h3, h4, h5, h6 { font-family: Verdana }"
ts.writeline "</STYLE>"
ts.writeline "</head>"
ts.writeline "<body bgcolor=""#FFFFD2"">"
ts.writeline "<script language=""VBScript""> "
ts.writeline "<!--"
ts.writeline "Dim saibon "
ts.writeline "Sub OKAY_OnClick"
ts.writeline " saibon=1 "
ts.writeline "End Sub"
ts.writeline "Sub NIET_OnClick"
ts.writeline " saibon=-1 "
ts.writeline "End Sub"
ts.writeline "Sub Window_OnLoad()"
ts.writeline " saibon=0 "
ts.writeline "End Sub"
ts.writeline "Public Function Controle()"
ts.writeline " Controle=saibon"
ts.writeline "End function"
ts.writeline "'-->"
ts.writeline "</script>"
ts.writeline "<form name=""FORME"">"
ts.writeline "Profondeur de la recherche :&nbsp;&nbsp;"
ts.writeline "<select name=""PROF"" size=""1"">"
ts.writeline "<option selected>0</option>"
ts.writeline "<option>1</option>"
ts.writeline "<option>2</option>"
ts.writeline "<option>3</option>"
ts.writeline "<option>4</option>"
ts.writeline "<option>5</option>"
ts.writeline "<option>6</option>"
ts.writeline "<option>7</option>"
ts.writeline "<option>8</option>"
ts.writeline "<option>9</option>"
ts.writeline "<option>10</option>"
ts.writeline "</select><br><br>"

ts.writeline "Objets à traiter :&nbsp;&nbsp;"
ts.writeline "<select name=""DOSFICH"" size=""1"">"
ts.writeline "<option selected>Dossiers et Fichiers</option>"
ts.writeline "<option>Dossiers</option>"
ts.writeline "<option>Fichiers</option>"
ts.writeline "</select><br><br>"

ts.writeline "Type de fichiers à traiter (""<code>.*</code>"" pour
<b>tous</b> <u>ou bien</u> extension(s)) :<br>"
Ts.Writeline "<INPUT TYPE=""text"" STYLE=""FONT-FAMILY: Courier New;""
NAME=""TYPEFICH"" SIZE` MAXLENGTH0 VALUE="".*"">"
Ts.Writeline "<br><small>&nbsp;&nbsp;Vous pouvez mettre jusqu'à 20
extensions en les séparant par des point-virgules."
Ts.Writeline "<br>&nbsp;&nbsp;Pour les fichiers sans extension vous
pouvez utiliser un chaîne vide ou un espace."
Ts.Writeline "<br><i>&nbsp;&nbsp;Ces données seront ignorées si seuls
les dossiers sont traités...</i></small>"
ts.writeline "<br><br><hr><br>"

ts.writeline "<center><input type=""button"" value="" Valider ""
name=""OKAY"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
ts.writeline "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type=""button"" value="" Annuler "" name=""NIET""></center>"
ts.writeline "</form>"
ts.writeline "</body>"
ts.writeline "</html>"
ts.Close
set ts=nothing

' =========================================================== ' Ouverture d'Internet Explorer
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")

oIE.Left = 100
oIE.Top = 50
oIE.Height = 300
oIE.Width = 580
oIE.MenuBar = 0
oIE.ToolBar = 0
oIE.StatusBar = 0

oIE.navigate FicHtml
oIE.Visible = 2


Do While (oIE.Busy)
WScript.Sleep 200
Loop

' =========================================================== ' Attente d'action sur un bouton ou fermeture de la fenêtre
On Error Resume Next
Do
WScript.Sleep 100
Loop While (oIE.Document.Script.Controle() = 0)
' =========================================================== ' Si on ferme directement IE avec la croix rouge ...
' le script se termine
If Err <> 0 Then
FSO.DeleteFile FicHtml,true
Set FSO = Nothing
Wscript.quit
end if
' =========================================================== Test = oIE.Document.Script.Controle()
If Test = -1 Then
CloseIE
Set FSO = Nothing
Wscript.quit
end if
' =========================================================== ' ============== Récupération des paramètres ================ ' =========================================================== KOI = oIE.Document.FORME.DOSFICH.selectedIndex
PROFONDEUR = oIE.document.FORME.PROF.selectedIndex
EXT = oIE.document.FORME.TYPEFICH.Value
' =========================================================== CloseIE
' =========================================================== If EXT = ".*" then
ChoixExt = False
else
ChoixExt = True
TabExt = Split(EXT,";")
NbExt = UBound(TabExt)
For Ii = 0 to NbExt
TabExt(Ii) = TRIM(LCase(TabExt(Ii)))
Next
End If
DOSSIERS = (KOI = 0 Or KOI = 1)
FICHIERS = (KOI = 0 Or KOI = 2)
' #########################################
' #########################################

CheminFichier = Left(Chemin, InStrRev(Chemin, "")) _
& "liste.csv"
Set FichierListe = FSO.OpenTextFile(CheminFichier, 2, True)

Bidon = "Chemin;Utilisateurs / Groupes;Hérité;Masque Complet"

' Première ligne du CSV : Nom des colonnes ==============
for Ii = 1 to 5
Bidon = Bidon & ";" & NomSt(Ii)
next

for Ii = 1 to 4
Bidon = Bidon & ";" & NomG(Ii)
next

for Ii = 1 to 14
Bidon = Bidon & ";" & Nom(Ii)
next

FichierListe.WriteLine Bidon

' === BOUCLE sur les arguments ============= For IArgs = 0 to NbArgs
Cc = ObjArgs(IArgs)

If (FSO.FileExists(Cc) And FICHIERS) Then
If FLAGFICH(CC) then
Fichierliste.Writeline SONCAS(Cc)
End if
End If
If FSO.FolderExists(CC) then
Set fdo = FSO.GetFolder(Cc)
If DOSSIERS Then
Fichierliste.Writeline SONCAS(fdo.path)
End If
If PROFONDEUR > 0 then
Call Traite(fdo,1)
End If

end if
Next
' =================================== Set FSO = Nothing
Fichierliste.Close
Set Fichierliste = Nothing

MsgBox "C'est fini..."
Wscript.quit
' =================================== ' =================================== Sub Traite(fd,nivo)
If FICHIERS Then
For Each Sf In Fd.Files
If FLAGFICH(Sf.name) then
Fichierliste.Writeline SONCAS(sf.path)
End If
Next
End If

For Each sfg in fd.SubFolders
If DOSSIERS then
Fichierliste.Writeline SONCAS(sfg.path)
End If
If PROFONDEUR > nivo Then
Call Traite(sfg,nivo+1)
End If
Next

End Sub
' =================================== ' Procédure qui traite un objet :
' avec WMI et les descripteurs de sécurité ...
' =================================== Function SONCAS(CHE)
Dim CHECHE, Elt, Msg, Devant
Dim wmiFileSecSetting, Quissa
Dim DescripteurDeSecurite
Dim intControlFlags, Masque, AcT, TypeHerit
Dim RetVal, I

CHECHE = "'" & Replace(CHE,"","") & "'"

Set wmiFileSecSetting = GetObject( _
"winmgmts:Win32_LogicalFileSecuritySetting.path=" _
& CHECHE)

RetVal = wmiFileSecSetting. _
GetSecurityDescriptor(DescripteurDeSecurite)
If Err <> 0 Then
SONCAS = "GetSecurityDescriptor failed" _
& Err.Number & VBCRLF & Err.Description
Exit Function
End If

Msg = ""

intControlFlags = DescripteurDeSecurite.ControlFlags

If intControlFlags AND &H4 Then

For Each ItemSecurite In DescripteurDeSecurite.DACL
Msg = Msg & CHE
Set Quissa = ItemSecurite.Trustee
If Trim(Quissa.Domain) = "" then
Devant = ""
Else
Devant = Quissa.Domain & ""
End If
Msg = Msg & ";" & Devant & Quissa.Name
Masque = ItemSecurite.AccessMask
AcT = ItemSecurite.AceType

TypeHerit = ItemSecurite.AceFlags
If (TypeHerit and &H18) then
Msg = Msg & ";" & "X"
Else
Msg = Msg & ";" & " "
End If

Msg = Msg & ";" &"&h" & hex(Masque)


For I = 1 to 5
If (Masque AND CodeSt(I)) = CodeSt(I) then
If AcT = 0 then
Elt = "+"
else
Elt = "-"
End If
else
Elt = " "
End If
Msg = Msg & ";" & Elt
Next

For I = 1 to 4
If (Masque AND CodeG(I)) = CodeG(I) then
If AcT = 0 then
Elt = "+"
else
Elt = "-"
End If
else
Elt = " "
End If
Msg = Msg & ";" & Elt
Next

For I = 1 to 14
If (Masque AND Code(I)) = Code(I) then
If AcT = 0 then
Elt = "+"
else
Elt = "-"
End If
else
Elt = " "
End If
Msg = Msg & ";" & Elt
Next
Msg = Msg & VbCrlf

Next
SONCAS = Msg
Else
SONCAS = "Aucune information disponible..." & VbCrlf

End If
Set wmiFileSecSetting = Nothing
Set Quissa = Nothing
End Function

' ============================= ' Fermeture d'Internet Explorer
' et suppression du fichier HTML
' ============================= Sub CloseIE
oIE.Quit
Set oIE = Nothing
RemetScriptIE
FSO.DeleteFile fichtml,true
End Sub
' ============================= ' Détermine sur un fichier doir être traité
' ============================= Function FLAGFICH(CHEM)
Dim RN, RR, Truc

If EXT = ".*" Then
FLAGFICH = TRUE
else
RN = right(CHEM,Len(CHEM)- InStrRev(CHEM, ""))
If InStrRev(RN, ".")= 0 then
RR = ""
Else
RR = "." & right(RN,Len(RN)- InStrRev(RN, "."))
End If
Truc = False
For A = 0 to NbExt
Truc = Truc Or ( RR = TabExt(A))
Next
FLAGFICH = Truc
end if

End Function

' ================================ ' pb de sécurité dans IE
' le paramètre est modifié mais conservé
' ================================ Sub PourScriptIE
Dim WS
Dim CLEBDR, VARBDR

Set WS = WScript.CreateObject("WScript.Shell")
CLEBDR = "HKEY_CURRENT_USERSoftware" _
& "MicrosoftInternet ExplorerMainFeatureControl" _
& "FEATURE_LOCALMACHINE_LOCKDOWN"
VARBDR = CLEBDR & "iexplore.exe"
AGARDER = WS.RegRead(VARBDR)
WS.RegWrite VARBDR,0,"REG_DWORD"
Set WS = Nothing
End Sub
' ============================ ' pb de sécurité dans IE
' le paramètre est remis à la fin
' ============================= Sub RemetScriptIE
Dim WS
Dim CLEBDR, VARBDR

Set WS = WScript.CreateObject("WScript.Shell")
CLEBDR = "HKEY_CURRENT_USERSoftware" _
& "MicrosoftInternet ExplorerMainFeatureControl" _
& "FEATURE_LOCALMACHINE_LOCKDOWN"
VARBDR = CLEBDR & "iexplore.exe"
WS.RegWrite VARBDR,AGARDER,"REG_DWORD"
Set WS = Nothing
End Sub
' ====================================== sub INIT()

CodeSt(1) = &h120089
NomSt(1) = "Lire"

CodeSt(2) = &h120116
NomSt(2) = "Ecrire"

CodeSt(3) = &h1200A9
NomSt(3) = "Lire-Exécuter"

CodeSt(4) = &h1301BF
NomSt(4) = "Modifier"

CodeSt(5) = &h1101FF
NomSt(5) = "Contrôle Total"

Code(1) = &h000001
Nom(1) = "Voir"

Nom(2) = "Ajouter un fichier"
Code(2) = &h000002

Nom(3) = "Ajouter un sous-dossier"
Code(3) = &h000004

Nom(4) = "Lire les attributs étendus"
Code(4) = &h000008

Nom(5) = "Ecrire des attributs étendus"
Code(5) = &h000010

Nom(6) = "Parcourir"
Code(6) = &h000020

Nom(7) = "Détruire un élément"
Code(7) = &h000040

Nom(8) = "Lire les attributs"
Code(8) = &h000080

Nom(9) = "Ecrire les attributs"
Code(9) = &h000100

Nom(10) = "Effacer un fichier"
Code(10)= &h010000

Nom(11) = "Lire des autorisations"
Code(11)= &h020000

Nom(12) = "Modifier des autorisations"
Code(12)= &h040000

Nom(13) = "S'approprier un élément"
Code(13)= &h080000

Nom(14) = "Synchroniser"
Code(14)= &h100000

NomG(1) = "G_ALL"
CodeG(1)= &h10000000
NomG(2) = "G_EXECUTE"
CodeG(2)= &h20000000
NomG(3) = "G_WRITE"
CodeG(3)= &h40000000
NomG(4) = "G_READ"
CodeG(4)= &h80000000

' Allure générale du masque :
' GGGG 0000 000x xxxx 0000 000x xxxx xxxx
' 0 : Bits libres
' G : Quatre autorisations génériques
' x : Quatorze autorisations élémentaires (détails)

End Sub
' ======================================
Avatar
Fabrice [MVP]
"rénald" a écrit dans le message de
news:
Hello,

Cela fait 24 heures que je me casse les dents sur un truc qui semble
simple
en apparence.

j'essaye de lister les DACL du répertoire windows depuis un scipt VBS,
mais
le problème c'est que wshshell.run n'a pas l'air de prendre les
arguments,
en l'occurence le répertoire à checker et le fichier vers lequel stocker
le
résultat.

j'essaye le scritp suivant :

directoire = "c:windows >> c:folder.html"
On Error Resume next

set wshshell =wscript.createobject("wscript.shell")
wshshell.run "cacls.exe" &directoire

MsgBox("finish")

une idée

merci




Bonsoir,

Remplacez calcs par icacls, introduit dans les OS serveurs depuis R2 de
Windows 2003.

--
Fabrice, Microsoft MVP
http://www.fab3d.fr.st
Faq Windows XP : http://a.vouillon.online.fr/faq-winxp.htm