;----------------------------------------------------------------------------------------------------------------------------- ;Copyright (©) 2004-2009 Jonathan BISMUTH, Bis-IT ;move_profil is free software ; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation ; ;move_profil is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ;You should have received a copy of the GNU General Public License along with Add2Local ; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ;Author : JOnathan BISMUTH, Bis-it. jbismuth@bis-it.fr; jonathan.bismuth@gmail.com ;Web site : http://blog.portail-mcse.net , http://www.bis-it.fr ;----------------------------------------------------------------------------------------------------------------------------- #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_res_language=1036 #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include Opt("ExpandEnvStrings", 1) $Dom = @LogonDomain $OS = @OSVersion $CurrentProfile = @UserProfileDir $currentuser = @UserName $nbr = $CmdLine[0] $prof = "C:\Documents and Settings\" if $nbr = "0" Then call ("Gui") else call ("Choice") EndIf func Choice() Select case $nbr >= 3 call ("Cmd") case $CmdLine[1] == "/?" call ("Help") exit case else msgbox (0, "Erreur de syntaxe", "Une erreur de syntaxe a eu lieu, utilisez le commutateur /? pour afficher l'aide") exit EndSelect EndFunc func Cmd() if $CmdLine[0] >= 4 and $CmdLine[4] = 1 Then $Move = 1 else $Move = 0 Endif $SourceProfile = $CmdLine[1] $CibleProfile = $CmdLine[2] $CiblePWD = $CmdLine[3] Call("newuser", $SourceProfile, $CibleProfile, $Dom, $prof, $CiblePWD, $Move) sleep (5000) Call("registry", $SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) sleep (5000) Call("registryOE", $SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) EndFunc func Gui() $list = _FileListToArray($prof) for $i=1 to $list[0] if stringinstr ($list[$i], "~") <>0 Then $NewName = StringReplace ($list[$i], "~", "") DirMove ($prof & $list[$i], $prof & $NewName) EndIf next $list = _FileListToArray($prof) for $i=1 to $list[0] if fileExists ($prof & $list[$i] & "\NTUSER.DAT") = 0 Then ;msgbox (0,"","existe pas dans " &$list[$i]) fileopen ($prof & $list[$i] & "\NTUSER.DAT", 1) EndIf next $max2 = $list[0] GUICreate("Outil de récupération des paramètres profils perdus v2.2", 550, 350) GUICtrlCreateLabel("Entrer le nom du profil source à récupérer, un seul choix possible parmi ceux-ci", 30, 30, 500, 20) $j = 3 $group_1 = GUICtrlCreateGroup("Profils sur le poste", 5, 15, 600, 300) GUIStartGroup() For $i = 1 To $max2 $Hj = 20 * $j $r2 = Assign("checkCN" & $i & "", GUICtrlCreateLabel("" & $list[$i], 30, $Hj, 120, 20), 2) ;$checkCN = GUICtrlCreateRadio ("" & $list[$i], 15,$Hj, 120, 20) GUICtrlSetState($r2, $GUI_CHECKED) $j = $j + 1 Next GUICtrlCreateLabel("Entrez le nom du profil du compte utilisateur source :", 250, 130, 500, 20) $SourceUsr = GUICtrlCreateInput("", 250, 160, 100, 20) GUICtrlCreateLabel("Entrez le nom du compte utilisateur cible :", 250, 190, 500, 20) $CibleUsr = GUICtrlCreateInput("", 250, 210, 100, 20) GUICtrlCreateLabel("Entrez le password du compte utilisateur cible :", 250, 240, 500, 20) $CiblePaWD = GUICtrlCreateInput("", 250, 270, 100, 20) $button_1 = GUICtrlCreateButton("OK", 435, 80, 90, 30) $MIR = GUICtrlCreateCheckbox("Copier le profil au lieu de déplacer?", 15, 330) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $button_1 $SourceProfile = GUICtrlRead($SourceUsr) $CibleProfile = GUICtrlRead($CibleUsr) $CiblePWD = GUICtrlRead($CiblePaWD) $Move = GUICtrlRead($MIR) If $SourceProfile = "" Or $CibleProfile = "" Then MsgBox(0, "erreur", "au moins un champs n'est pas rempli, sortie du programme...") Exit EndIf Call("newuser", $CibleProfile, $Dom, $CiblePWD) sleep (5000) Call("registry", $SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) sleep (5000) Call("registryOE", $SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) EndSelect WEnd EndFunc Func newuser($SourceProfile, $CibleProfile, $Dom, $prof, $CiblePWD, $Move) ;authentification du nouvel utilisateur FileInstall("dummy.exe", "c:\dummy.exe", 1) RunAsSet($CibleProfile, $Dom, $CiblePWD,1) run ("c:\dummy.exe") RunAsSet() FileDelete("c:\dummy.exe") ;détection du chemin de profil du nouvel utilisateur $aAccount = _Security__LookupAccountName("" & $Dom & "\" & $CibleProfile) Global $CibleProfileFull = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $aAccount[0] & "\", "ProfileImagePath") sleep (5000) FileInstall("robocopy.exe", "c:\robocopy.exe", 1) If $Move <> 1 Then $PSTMove = RunWait(@ComSpec & ' /c ' & 'c:\robocopy.exe /MOVE "' & $prof & '' & $SourceProfile & '" "' & $CibleProfileFull & '" /E /XF NTUSER.DAT NTUSER.DAT.LOG /XD "Temporary Internet Files" Temp') Else $PSTMove = RunWait(@ComSpec & ' /c ' & 'c:\robocopy.exe "' & $prof & '' & $SourceProfile & '" "' & $CibleProfileFull & '" /E /XF NTUSER.DAT NTUSER.DAT.LOG /XD "Temporary Internet Files" Temp') EndIf EndFunc ;==>newuser Func registry($SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) ;### ajout des paramètres du registre FileInstall("reg.exe", "c:\rege.exe", 1) $LoadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe load HKLM\temporaire "' & $prof & '' & $SourceProfile & '\ntuser.dat"') $ExportSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe export HKLM\temporaire\Software "' & $CibleProfileFull & '\bureau\profileoutlook.reg"') $UnloadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe unload HKLM\temporaire"') ;traitement du fichier du registre exporté $LoadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe load HKLM\temporaire "' & $CibleProfileFull & '\ntuser.dat"') $ImportSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe import "' & $CibleProfileFull & '\bureau\profileoutlook.reg"') $UnloadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe unload HKLM\temporaire"') FileDelete($CibleProfileFull & '\bureau\profileoutlook.reg') EndFunc ;==>registry Func registryOE($SourceProfile, $Dom, $CibleProfile, $prof, $CiblePWD,$CibleProfileFull) ;### ajout des paramètres du registre $LoadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe load HKLM\temporaire "' & $prof & '' & $SourceProfile & '\ntuser.dat"') $ExportSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe export HKLM\temporaire\Identities "' & $CibleProfileFull & '\bureau\identity.reg"') $UnloadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe unload HKLM\temporaire"') ;traitement du fichier du registre exporté $LoadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe load HKLM\temporaire "' & $CibleProfileFull & '\ntuser.dat"') $ImportSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe import "' & $CibleProfileFull & '\bureau\identity.reg"') $UnloadSourceReg = RunWait(@ComSpec & ' /c ' & 'c:\rege.exe unload HKLM\temporaire"') FileDelete($CibleProfileFull & '\bureau\identity.reg') MsgBox(0, "", "fin d'exécution de l'outil") FileDelete("c:\rege.exe") FileDelete("c:\robocopy.exe") Exit EndFunc ;==>registry func Help() msgbox (0, "Syntaxe","Sans arguments lance la version graphique, sinon :"& @LF &""& @LF &"Arguments Obligatoires"& @LF &""& @LF &"- Argument 1 : le dossier profil à migrer (préfixé automatiquement). Exemple : user1.machine1"& @LF &"- Argument 2 : nom de l'utilisateur du domaine pour qui migrer le profil "& @LF &" Argument 3 : mot de passe du compte pour qui migrer le profil"& @LF &""& @LF &"Argument facultatif"& @LF &""& @LF &"- Argument 4 : mettre à 1 si l'on souhaite copier les données plutot que de les déplacer."& @LF) EndFunc