From: francois on
I'm sorry Pegasus for my mail, I wanted to post on the
forum. I start again.


Pegasus [MVP] wrote :

> You could use the trusty old psexec.exe utility from www.sysinternals.com.

Ok thanks. This command (psexec) is very good. So, here is
my script. This script needs the "psexec" command to be
installed in the local PC and needs the "fileacl" command to
be installed in the (local or remote) PC where the folder is
created.

Finally, I use the "fileacl" command to set the NTFS rights
because the management is more precise than "cacls".

I'm sorry but the names of the variables are in French and
I'm too lazy to change them. If you have any remarks, don't
hesitate. The script seems to work well.


'-------------------------------------------------------
Function creeDossier(posteCible, cheminAbsolu, droits,
partage, nomDePartage)
Dim posteCibleTemp, cheminAbsoluTemp, objRegExp
Dim nomDePartageTemp, commande_partage,
commande_fileacl
Dim emplacement, nom_dossier, lecteur
Dim chemin_UNC_local, cheminComplet_UNC_local
Dim objFSO, objShell
posteCibleTemp = UCase(posteCible)
cheminAbsoluTemp = Trim(Replace(cheminAbsolu, "/",
"\"))
nomDePartageTemp = Trim(nomDePartage)
commande_partage = "net share " & nomDePartageTemp
& "=" & Chr(34) & cheminAbsoluTemp & Chr(34) & " /UNLIMITED"
commande_fileacl = "fileacl.exe " & Chr(34) &
cheminAbsoluTemp & Chr(34) & " " & droits
'Wscript.Echo commande_partage
'Wscript.Echo commande_fileacl
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = False
objRegExp.Pattern = "^([a-z]):(.*\\)([^\\]+)\\?$"
'On teste la chaine cheminAbsoluTemp qui doit �tre
de la forme
'<lecteur>:<emplacement><nom_dossier>
If Not objRegExp.test(cheminAbsoluTemp) Then
Wscript.Echo "D�sol�, le chemin " &
cheminAbsoluTemp & " n'est pas valide."
creeDossier = -1
Exit Function
Else
lecteur = objRegexp.Replace(cheminAbsoluTemp, "$1")
emplacement =
objRegexp.Replace(cheminAbsoluTemp, "$2")
nom_dossier =
objRegexp.Replace(cheminAbsoluTemp, "$3")
'Wscript.Echo "Le lecteur : " & lecteur
'Wscript.Echo "L'emplacement : " & emplacement
'Wscript.Echo "Le nom du dossier : " & nom_dossier
End If
'On teste si le poste cible est le poste local ou non
'Si ce n'est pas en local, on change
commande_partage et commande_fileacl
If posteCibleTemp = Me.poste_local Then
chemin_UNC_local = lecteur & ":" & emplacement
Else
chemin_UNC_local = "\\" & posteCibleTemp & "\"
& lecteur & "$" & emplacement
commande_partage = "psexec.exe \\" &
posteCibleTemp & " " & commande_partage
commande_fileacl = "psexec.exe \\" &
posteCibleTemp & " " & commande_fileacl
'Wscript.Echo commande_partage
'Wscript.Echo commande_fileacl
End If
cheminComplet_UNC_local = chemin_UNC_local &
nom_dossier
'Wscript.Echo "Le chemin UNC ou local : " &
chemin_UNC_local
'Wscript.Echo "Le chemin complet UNC ou local : " &
cheminComplet_UNC_local
'On teste si chemin_UNC_local existe et si
cheminComplet_UNC_local n'exite pas
'Si ce n'est pas le cas, la fonction s'arr�te.
Set objFSO =
WScript.CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(chemin_UNC_local) Then
Wscript.Echo "D�sol� mais le dossier " &
chemin_UNC_local & " n'existe pas."
creeDossier = -1
Exit Function
End If
If objFSO.FolderExists(cheminComplet_UNC_local) Then
Wscript.Echo "D�sol� mais le dossier " &
cheminComplet_UNC_local & " existe d�j�."
creeDossier = -1
Exit Function
End If
'Enfin, on peut cr�er le dossier
Call objFSO.CreateFolder(cheminComplet_UNC_local)
'On partage le dossier si cela est demand�
If partage Then
Set objShell = WScript.CreateObject
("WSCript.shell")
Call objShell.Run(commande_partage, 0, True)
End If
'Si droits n'est pas une chaine vide, alors on
param�tre les
'droits avec fileacl.exe
If Not droits = "" Then
Set objShell = WScript.CreateObject
("WSCript.shell")
Call objShell.Run(commande_fileacl, 0, True)
End If
creeDossier = 0
End Function
'-------------------------------------------------------



--
Fran�ois Lafont
From: francois on
Al Dunbar a �crit :

> As a suggestion, why not delete the "share" parameter? If the sharename
> parameter is a string, then share the folder using that name. If it is
> a boolean like "false", then don't share.

Yes, it's a good suggestion.

> CACLS doesn't need a local path

Yes indeed. :-)
But "net share" needs a local path. In fact, I think the
"psexec" command solves my problem.



--
Fran�ois Lafont
From: Pegasus [MVP] on


"francois" <francois(a)NoSpam.fr> said this in news item
news:uNt6rirpKHA.5224(a)TK2MSFTNGP05.phx.gbl...
> I'm sorry Pegasus for my mail, I wanted to post on the forum. I start
> again.
>
>
> Pegasus [MVP] wrote :
>
>> You could use the trusty old psexec.exe utility from
>> www.sysinternals.com.
>
> Ok thanks. This command (psexec) is very good. So, here is
> my script. This script needs the "psexec" command to be
> installed in the local PC and needs the "fileacl" command to
> be installed in the (local or remote) PC where the folder is
> created.
>
> Finally, I use the "fileacl" command to set the NTFS rights
> because the management is more precise than "cacls".
>

Looks good - thanks for the feedback.