djsweaty Posted February 5, 2009 Share Posted February 5, 2009 I need help trying to complete the idea of scanning and moving an AD Home folder. My problem is that I don't know where to start. I want to be able to scan each Home folder for certain folders if they are not there create folder and move on to the next user folder until all is completed. After completed, I want to be able to move all folders to a different cluster. Better yet after each folder check/creation, the folder would be moved. Can someone help me out? I am definately a beginner with AutoIt V3, used it several times for small things. Now what I need is a bit beyond my knowledge. The attached script actually creates a folder in a users profile, that you input. The profiles are on a AD network share. Instead of handling one by one, I want to check each folder in a directory and create specific folders. After the folders are created, I want to move each profile folder to a different Share. I've tried reading and understanding different things, but I'm still stuck. Can anyone help? expandcollapse popupIf Not IsDeclared("sServer") Then Local $sServer $sServer = InputBox("Select a domain","Enter domain server name for profile",""," M12","-1","-1","-1","-1") Select Case @Error = 0 ;Valid entry Case @Error = 1 ;Cancel Case @Error = 3 ;Input error EndSelect If @error = 1 Then MsgBox(4096, "AutoIt", "Action Cancelled!") Exit EndIf Do If Not IsDeclared("sProfileName") Then Local $sProfileName $sProfileName = InputBox("Profile Path", "The Domain your using is: " & $sServer & " Enter the Users Profile Path?", "", " 13") Select Case @error = 0 ;valid Case @error = 1 ;Cancel Case @error = 3 ;Failed Input Box EndSelect If @error = 1 Then MsgBox(4096, "AutoIt", "Action Cancelled!") Exit EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName) Then If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\Scans") Then MsgBox(64, "", "Scans Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\Scans") MsgBox(64, "", "Scans Folder Successfully Created", 2) EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\Outlook Archive") Then MsgBox(64, "", "Archive Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\Outlook Archive") MsgBox(64, "", "Outlook Archive Folder Successfully Created", 2) EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\My PKI") Then MsgBox(64, "", "PKI Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\My PKI") MsgBox(64, "", "My PKI Folder Successfully Created", 2) EndIf Else MsgBox(64, "", "The profile " & $sProfileName & " does not exist on server. Please try again.", 20) EndIf Until @error = 1 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 6, 2009 Share Posted February 6, 2009 (edited) I need help trying to complete the idea of scanning and moving an AD Home folder. My problem is that I don't know where to start. I want to be able to scan each Home folder for certain folders if they are not there create folder and move on to the next user folder until all is completed. After completed, I want to be able to move all folders to a different cluster. Better yet after each folder check/creation, the folder would be moved. Can someone help me out? I am definately a beginner with AutoIt V3, used it several times for small things. Now what I need is a bit beyond my knowledge. The attached script actually creates a folder in a users profile, that you input. The profiles are on a AD network share. Instead of handling one by one, I want to check each folder in a directory and create specific folders. After the folders are created, I want to move each profile folder to a different Share. I've tried reading and understanding different things, but I'm still stuck. Can anyone help? CODEIf Not IsDeclared("sServer") Then Local $sServer $sServer = InputBox("Select a domain","Enter domain server name for profile",""," M12","-1","-1","-1","-1") Select Case @Error = 0;Valid entry Case @Error = 1;Cancel Case @Error = 3;Input error EndSelect If @error = 1 Then MsgBox(4096, "AutoIt", "Action Cancelled!") Exit EndIf Do If Not IsDeclared("sProfileName") Then Local $sProfileName $sProfileName = InputBox("Profile Path", "The Domain your using is: " & $sServer & " Enter the Users Profile Path?", "", " 13") Select Case @error = 0;valid Case @error = 1;Cancel Case @error = 3;Failed Input Box EndSelect If @error = 1 Then MsgBox(4096, "AutoIt", "Action Cancelled!") Exit EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName) Then If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\Scans") Then MsgBox(64, "", "Scans Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\Scans") MsgBox(64, "", "Scans Folder Successfully Created", 2) EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\Outlook Archive") Then MsgBox(64, "", "Archive Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\Outlook Archive") MsgBox(64, "", "Outlook Archive Folder Successfully Created", 2) EndIf If FileExists("\\" & $sServer & "\users\" & $sProfileName & "\My PKI") Then MsgBox(64, "", "PKI Folder Already Exists", 1) Else DirCreate("\\" & $sServer & "\users\" & $sProfileName & "\My PKI") MsgBox(64, "", "My PKI Folder Successfully Created", 2) EndIf Else MsgBox(64, "", "The profile " & $sProfileName & " does not exist on server. Please try again.", 20) EndIf Until @error = 1 Cleaned up to demonstrate better handling of error from InputBox(), putting repetitive strings in variables, and putting repetitive code into a function: expandcollapse popupGlobal $sServer, $sUsersShare, $sProfileName, $sProfilePath $sServer = InputBox("Select Server", "Enter domain server name for profile:") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit Else $sUsersShare = "\\" & $sServer & "\Users" If Not FileExists($sUsersShare & "\") Then MsgBox(16, "Error!", "No USERS share available: " & $sUsersShare) Exit EndIf EndIf While $sProfileName = InputBox("Profile Name", "Users Path = " & $sServer & "; Enter Profile Name:") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit EndIf $sProfilePath = $sUsersShare & "\" & $sProfileName If FileExists($sProfilePath & "\") Then _CheckAndCreate($sProfilePath & "\Scans") _CheckAndCreate($sProfilePath & "\Outlook Archive") _CheckAndCreate($sProfilePath & "\My PKI") Else MsgBox(16, "Error!", "Profile path does not exist: " & $sProfilePath) EndIf WEnd Func _CheckAndCreate($sPath) If FileExists($sPath) Then MsgBox(64, "Already Exists", "Folder already exists: " & $sPath, 2) Else If DirCreate($sPath) Then MsgBox(64, "Success", "Folder successfully created: " & $sPath, 2) Else MsgBox(16, "Error!", "Failed to create folder: " & $sPath) EndIf EndIf EndFunc ;==>_CheckAndCreate Once cleaned up, it is easier to plan where you want the copy part inserted. Edited February 6, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
djsweaty Posted February 11, 2009 Author Share Posted February 11, 2009 Wow, you made it understanding for me quite a bit of how to clean it up. I will try to work with the rest. From the While is were I would add the DirMove command? Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 11, 2009 Share Posted February 11, 2009 Wow, you made it understanding for me quite a bit of how to clean it up. I will try to work with the rest. From the While is were I would add the DirMove command?I don't know what "From the While" means. Maybe you should look at it again. Think through the While loop and plan at what point you would want to do the move. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
djsweaty Posted February 14, 2009 Author Share Posted February 14, 2009 Thanks for your help big time. Sorry about the "While", I had confused myself. Do to the complexity of how previous Administrator's setup the OU's and roaming profiles, I feel I cannot move all the users at one time. When we move the user to the new OU, they will not have a roaming profile, only a home path. Here is what I am trying to do now in the following order. All of the above code will be used, but I need some serious help with what I need now. a. Get $sServer (Already established code) b. Get $sUserprofile (Already established code) c. Create folders in old share (Already established code) d. Search for *.pst and *.pki and move to specific folders (Having issues searching entire user share folder for file) e. Move user from OU=Users to OU=New Users in AD (Having problem with code, keeps erroring out using the dsmove command, same domain) f. Change users Home path and drive letter (Having same problem as previous) g. Delete user profile path (Having same problem as previous) h. Move users home folder to new server home folder (Already established code) Now, my major problem is getting dsmove to work properly. I have search the web for the last three days and everything I've found provides the same format. The error I keep getting is "OU=USERS, OU=MY" is an unknown parameter. The problem is, that's not the whole path that I'm using. I verified the entire path using an AD software that I forgot the name because I'm at home. I tried it with VBS and still get the same/similar error. When using the dsmove command it looks like this: Run (@Comspec, "dsmove CN=$sUserprofile, OU=Users, OU=My North Winds (NMW), OU=Tree1, DC=domain, DC=for, DC=is, DC=com" -newparent OU=New Users, OU=My North Winds (NMW), OU=Tree1, DC=domain, DC=for, DC=is, DC=com) Here's what the AD tree looks like when looking at it from Users and Computers: for.is.com -Domain -Tree1 -My North Winds (NMW) - Users User1 User2 User3 ..... Somehow, the spaces in CN=My North Winds (NMW) are not recognizing at all. Again, even with a vbs script it does the same thing. I've tried every senerio, even placing My North ... in double quotes, single-lined quotes, and brackets. Still I get the same error. I've spent many hours on this and I can't figure it out. I've even used several different variations of vbs scripts (see below) to just even look in AD for specific user and I get the same error. So something has to be up with either my placements of quotes or dsmove doesn't like spaces. Seems like everyone has been having issues with dsmove that I've seen online. Any help or guidance will be greatly appreciated. Set objNewOU = GetObject("LDAP://OU=Users, OU=My North Winds (NMW), OU=Tree1, DC=domain, DC=for, DC=is, DC=com") Set objMoveUser = objNewOU.MoveHere _ ("LDAP://OU= New Users, OU=My North Winds (NMW), OU=Tree1, DC=domain, DC=for, DC=is, DC=com) Thanks in advance. DJ Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 14, 2009 Share Posted February 14, 2009 (edited) I am not where I can test this on a domain, but this should work for the DSMove method: Global $sUserName = 'CN=UserName,OU=Old Users OrgUnit,DC=MYDOMAIN,DC=com' Global $sNewParent = 'OU=New Users OrgUnit,DC=MYDOMAIN,DC=com' $RET = RunWait(@ComSpec & ' /k dsmove "' & $sUserName & '" -newparent "' & $sNewParent & '"') Your quoting and string handling looked all wrong in your example for this. Note double-quotes around both LDAP path strings, and single-quotes to enclose the literal double-quotes. P.S. There are many working examples of recursive file searches posted. The forum search is your friend. Edited February 14, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
djsweaty Posted February 15, 2009 Author Share Posted February 15, 2009 (edited) OK, this darn dsmove command is a serious pain in the you know what. It seems I'm getting past the first part of the dsmove, but I'm not even sure about that. Now I'm getting the following error on the -newparent. dsmove failed:Value for `Target object for this command' has incorrect format. I've tried everything using "",'', (), <> to get this thing to work. I've even tried doing a -newname and get the same error. What gives? I also got this error at one time too: OU was unexpected at this time Edited February 15, 2009 by djsweaty Link to comment Share on other sites More sharing options...
djsweaty Posted February 23, 2009 Author Share Posted February 23, 2009 Ok, I finally found out what my problem was. I didn't need to put the entire path on the DSMOVE. Here is my script. If you can help me make it better, please provide some guidance. I used a func from someone else to get a progress bar. The other problem I have, if the a users profile is not found, my script runs all the ELSE commands. How do I get it to restart the script again?CODE#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Res_Comment=This file moves the user from OU=Users to OU=Users New. This script also calls clearpro.vbs to clear the profile field. This script can be used on Users that are already on OU=Users New to perform actions.#AutoIt3Wrapper_Res_Description=Automated Move of a user to OU=Users New#AutoIt3Wrapper_Res_Fileversion=0.0.0.2#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y#AutoIt3Wrapper_res_requestedExecutionLevel=requireAdministrator#AutoIt3Wrapper_Run_Tidy=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#Region constsGlobal Const $FO_MOVE = 0x0001Global Const $FO_COPY = 0x0002Global Const $FO_DELETE = 0x0003Global Const $FO_RENAME = 0x0004Global Const $FOF_MULTIDESTFILES = 0x0001Global Const $FOF_CONFIRMMOUSE = 0x0002Global Const $FOF_SILENT = 0x0004Global Const $FOF_RENAMEONCOLLISION = 0x0008Global Const $FOF_NOCONFIRMATION = 0x0010Global Const $FOF_WANTMAPPINGHANDLE = 0x0020Global Const $FOF_ALLOWUNDO = 0x0040Global Const $FOF_FILESONLY = 0x0080Global Const $FOF_SIMPLEPROGRESS = 0x0100Global Const $FOF_NOCONFIRMMKDIR = 0x0200Global Const $FOF_NOERRORUI = 0x0400Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800Global Const $FOF_NORECURSION = 0x1000Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000Global Const $FOF_WANTNUKEWARNING = 0x4000Global Const $FOF_NORECURSEREPARSE = 0x8000#EndRegion constsGlobal $sServer, $sUsersShare, $sProfileName, $sProfilePath, $sOldProfilePathGlobal $sOldRoamProfile = "oldroamingprofilefolder"Global $sNewParent = '""'Global $sNewServer = "\\newprofileserver\users\"$sServer = InputBox("Select Server", "Enter domain server name for profile:", "") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit Else $sUsersShare = "\\" & $sServer & "\Users" If Not FileExists($sUsersShare & "\") Then MsgBox(16, "Error!", "No USERS share available: " & $sUsersShare) Exit EndIf EndIfDo $sProfileName = InputBox("Profile Name", "Users Path = " & $sServer & "; Enter Profile Name:", "") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit EndIf $sProfilePath = $sUsersShare & "\" & $sProfileName If FileExists($sProfilePath & "\") Then _CheckAndCreate($sProfilePath & "\My Scans") _CheckAndCreate($sProfilePath & "\My Outlook Archive") _CheckAndCreate($sProfilePath & "\My PKI") _CheckAndCreate($sProfilePath & "\My Favorites") Else MsgBox(16, "Error!", "Profile path does not exist: " & $sProfilePath) EndIf If FileExists($sProfilePath & "\*.pfx") Then MsgBox(64, "PKI Search", "Users PKI has been found. Moving to My PKI Folder", 2) FileMove($sProfilePath & "\*.pfx", $sProfilePath & "\My PKI") Else MsgBox(16, "PKI Search...", "Users PKI not found in root folder.", 2) EndIf If FileExists($sProfilePath & "\*.pst") Then MsgBox(64, "Mail Archive Search", "Users mail archive has been found. Moving to My Outlook Archive folder", 2) FileMove($sProfilePath & "\*.pst", $sProfilePath & "\My Outlook Archive") Else MsgBox(16, "Mail Archive Search...", "An Outlook Archive was not found in root folder.", 2) EndIf If $sServer = "oldservername" Then If FileExists("\\oldroamingprofile\profiles\" & $sProfileName & "\Favorites") Then FileCopy($sOldRoamProfile & $sProfileName & "\Favorites\*.*", "\\" & $sServer & "\users\" & $sProfileName & "\My Favorites\") _CopyWithProgress($sProfilePath, "\\newprofileserver\users\") Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmove -newparent ' & $sNewParent) Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -hmdrv P:') Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -hmdir \\newserverprovile\users\' & $sProfileName) ;; Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -profile " "') RunWait(@ComSpec & ' /c clearPro.vbs') RunWait(DirRemove("\\oldprofileserver\users\" & $sProfileName, 1)) RunWait(DirRemove("\\oldroamingprofile\profiles\" & $sProfileName, 1)) Else MsgBox(64, "", "A profile folder for " & $sProfileName & " did not exist on source " & $sServer & " server.", 2) EndIf Else EndIfUntil @error = 0Func _CheckAndCreate($sPath) If FileExists($sPath) Then MsgBox(64, "Already Exists", "Folder already exists: " & $sPath, 2) Else If DirCreate($sPath) Then MsgBox(64, "Success", "Folder successfully created: " & $sPath, 2) Else MsgBox(16, "Error!", "Failed to create folder: " & $sPath) EndIf EndIfEndFunc ;==>_CheckAndCreateFunc _CopyWithProgress($sFrom, $sTo) ; version 1 by SumTingWong on 5/26/2006 ; http://www.autoitscript.com/forum/index.php?showtopic=11888 ; updated by lod3n on 6/5/2007 Local $SHFILEOPSTRUCT Local $pFrom Local $pTo Local $aDllRet Local $nError = 0 Local $i $SHFILEOPSTRUCT = DllStructCreate("int;uint;ptr;ptr;uint;int;ptr;ptr") If @error Then Return "nostruct" ; hwnd DllStructSetData($SHFILEOPSTRUCT, 1, 0) ; wFunc DllStructSetData($SHFILEOPSTRUCT, 2, $FO_COPY) ; pFrom $pFrom = DllStructCreate("char[" & StringLen($sFrom) + 2 & "]") ; pFrom will now be null-terminated at StringLen($sFrom)+1 DllStructSetData($pFrom, 1, $sFrom) For $i = 1 To StringLen($sFrom) + 2 If DllStructGetData($pFrom, 1, $i) = 10 Then DllStructSetData($pFrom, 1, 0, $i) Next ; We need a second null at the end DllStructSetData($pFrom, 1, 0, StringLen($sFrom) + 2) DllStructSetData($SHFILEOPSTRUCT, 3, DllStructGetPtr($pFrom)) ; pTo $pTo = DllStructCreate("char[" & StringLen($sTo) + 2 & "]") ; pTo will now be null-terminated at StringLen($sTo)+1 DllStructSetData($pTo, 1, $sTo) ; We need a second null at the end DllStructSetData($pTo, 1, 0, StringLen($sTo) + 2) DllStructSetData($SHFILEOPSTRUCT, 4, DllStructGetPtr($pTo)) ; fFlags DllStructSetData($SHFILEOPSTRUCT, 5, BitOR($FOF_NOCONFIRMMKDIR, _ $FOF_NOCONFIRMATION, _ $FOF_NOERRORUI)) ; fAnyOperationsAborted DllStructSetData($SHFILEOPSTRUCT, 6, 0) ; hNameMappings DllStructSetData($SHFILEOPSTRUCT, 7, 0) ; lpszProgressTitle DllStructSetData($SHFILEOPSTRUCT, 8, 0) $aDllRet = DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT)) $retcode = $aDllRet[0] $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $retcode <> 0 Then ConsoleWrite(Hex($retcode) & ": " & SHFileOperationErrDecode($retcode) & @CRLF) SetError($nError) Return False EndIf Return TrueEndFunc ;==>_CopyWithProgressFunc SHFileOperationErrDecode($errNum) Switch $errNum Case 113 Return "The source and destination files are the same file." Case 114 Return "Multiple file paths were specified in the source buffer, but only one destination file path." Case 115 Return "Rename operation was specified but the destination path is a different directory. Use the move operation instead." Case 116 Return "The source is a root directory, which cannot be moved or renamed." Case 117 Return "The operation was cancelled by the user, or silently cancelled if the appropriate flags were supplied to SHFileOperation." Case 118 Return "The destination is a subtree of the source." Case 120 Return "Security settings denied access to the source." Case 121 Return "The source or destination path exceeded or would exceed MAX_PATH." Case 122 Return "The operation involved multiple destination paths, which can fail in the case of a move operation." Case 124 Return "The path in the source or destination or both was invalid." Case 125 Return "The source and destination have the same parent folder." Case 126 Return "The destination path is an existing file." Case 128 Return "The destination path is an existing folder." Case 129 Return "The name of the file exceeds MAX_PATH." Case 130 Return "The destination is a read-only CD-ROM, possibly unformatted." Case 131 Return "The destination is a read-only DVD, possibly unformatted." Case 132 Return "The destination is a writable CD-ROM, possibly unformatted." Case 133 Return "The file involved in the operation is too large for the destination media or file system." Case 134 Return "The source is a read-only CD-ROM, possibly unformatted." Case 135 Return "The source is a read-only DVD, possibly unformatted." Case 136 Return "The source is a writable CD-ROM, possibly unformatted." Case 183 Return "MAX_PATH was exceeded during the operation." Case 1026 Return "An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Microsoft Windows Vista and later." Case 65536 Return "An unspecified error occurred on the destination." Case 65652 Return "Destination is a root directory and cannot be renamed." EndSwitch Return "SHFileOperation returned errorcode " & Hex($errNum) & ", which is not recognized"EndFunc ;==>SHFileOperationErrDecode'; Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 23, 2009 Share Posted February 23, 2009 Ok, I finally found out what my problem was. I didn't need to put the entire path on the DSMOVE. Here is my script. If you can help me make it better, please provide some guidance. I used a func from someone else to get a progress bar. The other problem I have, if the a users profile is not found, my script runs all the ELSE commands. How do I get it to restart the script again? CODE#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Comment=This file moves the user from OU=Users to OU=Users New. This script also calls clearpro.vbs to clear the profile field. This script can be used on Users that are already on OU=Users New to perform actions. #AutoIt3Wrapper_Res_Description=Automated Move of a user to OU=Users New #AutoIt3Wrapper_Res_Fileversion=0.0.0.2 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #AutoIt3Wrapper_res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Region consts Global Const $FO_MOVE = 0x0001 Global Const $FO_COPY = 0x0002 Global Const $FO_DELETE = 0x0003 Global Const $FO_RENAME = 0x0004 Global Const $FOF_MULTIDESTFILES = 0x0001 Global Const $FOF_CONFIRMMOUSE = 0x0002 Global Const $FOF_SILENT = 0x0004 Global Const $FOF_RENAMEONCOLLISION = 0x0008 Global Const $FOF_NOCONFIRMATION = 0x0010 Global Const $FOF_WANTMAPPINGHANDLE = 0x0020 Global Const $FOF_ALLOWUNDO = 0x0040 Global Const $FOF_FILESONLY = 0x0080 Global Const $FOF_SIMPLEPROGRESS = 0x0100 Global Const $FOF_NOCONFIRMMKDIR = 0x0200 Global Const $FOF_NOERRORUI = 0x0400 Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800 Global Const $FOF_NORECURSION = 0x1000 Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000 Global Const $FOF_WANTNUKEWARNING = 0x4000 Global Const $FOF_NORECURSEREPARSE = 0x8000 #EndRegion consts Global $sServer, $sUsersShare, $sProfileName, $sProfilePath, $sOldProfilePath Global $sOldRoamProfile = "oldroamingprofilefolder" Global $sNewParent = '""' Global $sNewServer = "\\newprofileserver\users\" $sServer = InputBox("Select Server", "Enter domain server name for profile:", "") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit Else $sUsersShare = "\\" & $sServer & "\Users" If Not FileExists($sUsersShare & "\") Then MsgBox(16, "Error!", "No USERS share available: " & $sUsersShare) Exit EndIf EndIf Do $sProfileName = InputBox("Profile Name", "Users Path = " & $sServer & "; Enter Profile Name:", "") If @error <> 0 Then MsgBox(16, "Error!", "Action Cancelled!", 10) Exit EndIf $sProfilePath = $sUsersShare & "\" & $sProfileName If FileExists($sProfilePath & "\") Then _CheckAndCreate($sProfilePath & "\My Scans") _CheckAndCreate($sProfilePath & "\My Outlook Archive") _CheckAndCreate($sProfilePath & "\My PKI") _CheckAndCreate($sProfilePath & "\My Favorites") Else MsgBox(16, "Error!", "Profile path does not exist: " & $sProfilePath) EndIf If FileExists($sProfilePath & "\*.pfx") Then MsgBox(64, "PKI Search", "Users PKI has been found. Moving to My PKI Folder", 2) FileMove($sProfilePath & "\*.pfx", $sProfilePath & "\My PKI") Else MsgBox(16, "PKI Search...", "Users PKI not found in root folder.", 2) EndIf If FileExists($sProfilePath & "\*.pst") Then MsgBox(64, "Mail Archive Search", "Users mail archive has been found. Moving to My Outlook Archive folder", 2) FileMove($sProfilePath & "\*.pst", $sProfilePath & "\My Outlook Archive") Else MsgBox(16, "Mail Archive Search...", "An Outlook Archive was not found in root folder.", 2) EndIf If $sServer = "oldservername" Then If FileExists("\\oldroamingprofile\profiles\" & $sProfileName & "\Favorites") Then FileCopy($sOldRoamProfile & $sProfileName & "\Favorites\*.*", "\\" & $sServer & "\users\" & $sProfileName & "\My Favorites\") _CopyWithProgress($sProfilePath, "\\newprofileserver\users\") Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmove -newparent ' & $sNewParent) Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -hmdrv P:') Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -hmdir \\newserverprovile\users\' & $sProfileName) ;; Run(@ComSpec & ' /c dsquery user -samid ' & $sProfileName & ' | dsmod user -profile " "') RunWait(@ComSpec & ' /c clearPro.vbs') RunWait(DirRemove("\\oldprofileserver\users\" & $sProfileName, 1)) RunWait(DirRemove("\\oldroamingprofile\profiles\" & $sProfileName, 1)) Else MsgBox(64, "", "A profile folder for " & $sProfileName & " did not exist on source " & $sServer & " server.", 2) EndIf Else EndIf Until @error = 0 Func _CheckAndCreate($sPath) If FileExists($sPath) Then MsgBox(64, "Already Exists", "Folder already exists: " & $sPath, 2) Else If DirCreate($sPath) Then MsgBox(64, "Success", "Folder successfully created: " & $sPath, 2) Else MsgBox(16, "Error!", "Failed to create folder: " & $sPath) EndIf EndIf EndFunc ;==>_CheckAndCreate Func _CopyWithProgress($sFrom, $sTo) ; version 1 by SumTingWong on 5/26/2006 ; http://www.autoitscript.com/forum/index.php?showtopic=11888 ; updated by lod3n on 6/5/2007 Local $SHFILEOPSTRUCT Local $pFrom Local $pTo Local $aDllRet Local $nError = 0 Local $i $SHFILEOPSTRUCT = DllStructCreate("int;uint;ptr;ptr;uint;int;ptr;ptr") If @error Then Return "nostruct" ; hwnd DllStructSetData($SHFILEOPSTRUCT, 1, 0) ; wFunc DllStructSetData($SHFILEOPSTRUCT, 2, $FO_COPY) ; pFrom $pFrom = DllStructCreate("char[" & StringLen($sFrom) + 2 & "]") ; pFrom will now be null-terminated at StringLen($sFrom)+1 DllStructSetData($pFrom, 1, $sFrom) For $i = 1 To StringLen($sFrom) + 2 If DllStructGetData($pFrom, 1, $i) = 10 Then DllStructSetData($pFrom, 1, 0, $i) Next ; We need a second null at the end DllStructSetData($pFrom, 1, 0, StringLen($sFrom) + 2) DllStructSetData($SHFILEOPSTRUCT, 3, DllStructGetPtr($pFrom)) ; pTo $pTo = DllStructCreate("char[" & StringLen($sTo) + 2 & "]") ; pTo will now be null-terminated at StringLen($sTo)+1 DllStructSetData($pTo, 1, $sTo) ; We need a second null at the end DllStructSetData($pTo, 1, 0, StringLen($sTo) + 2) DllStructSetData($SHFILEOPSTRUCT, 4, DllStructGetPtr($pTo)) ; fFlags DllStructSetData($SHFILEOPSTRUCT, 5, BitOR($FOF_NOCONFIRMMKDIR, _ $FOF_NOCONFIRMATION, _ $FOF_NOERRORUI)) ; fAnyOperationsAborted DllStructSetData($SHFILEOPSTRUCT, 6, 0) ; hNameMappings DllStructSetData($SHFILEOPSTRUCT, 7, 0) ; lpszProgressTitle DllStructSetData($SHFILEOPSTRUCT, 8, 0) $aDllRet = DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT)) $retcode = $aDllRet[0] $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $retcode <> 0 Then ConsoleWrite(Hex($retcode) & ": " & SHFileOperationErrDecode($retcode) & @CRLF) SetError($nError) Return False EndIf Return True EndFunc ;==>_CopyWithProgress Func SHFileOperationErrDecode($errNum) Switch $errNum Case 113 Return "The source and destination files are the same file." Case 114 Return "Multiple file paths were specified in the source buffer, but only one destination file path." Case 115 Return "Rename operation was specified but the destination path is a different directory. Use the move operation instead." Case 116 Return "The source is a root directory, which cannot be moved or renamed." Case 117 Return "The operation was cancelled by the user, or silently cancelled if the appropriate flags were supplied to SHFileOperation." Case 118 Return "The destination is a subtree of the source." Case 120 Return "Security settings denied access to the source." Case 121 Return "The source or destination path exceeded or would exceed MAX_PATH." Case 122 Return "The operation involved multiple destination paths, which can fail in the case of a move operation." Case 124 Return "The path in the source or destination or both was invalid." Case 125 Return "The source and destination have the same parent folder." Case 126 Return "The destination path is an existing file." Case 128 Return "The destination path is an existing folder." Case 129 Return "The name of the file exceeds MAX_PATH." Case 130 Return "The destination is a read-only CD-ROM, possibly unformatted." Case 131 Return "The destination is a read-only DVD, possibly unformatted." Case 132 Return "The destination is a writable CD-ROM, possibly unformatted." Case 133 Return "The file involved in the operation is too large for the destination media or file system." Case 134 Return "The source is a read-only CD-ROM, possibly unformatted." Case 135 Return "The source is a read-only DVD, possibly unformatted." Case 136 Return "The source is a writable CD-ROM, possibly unformatted." Case 183 Return "MAX_PATH was exceeded during the operation." Case 1026 Return "An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Microsoft Windows Vista and later." Case 65536 Return "An unspecified error occurred on the destination." Case 65652 Return "Destination is a root directory and cannot be renamed." EndSwitch Return "SHFileOperation returned errorcode " & Hex($errNum) & ", which is not recognized" EndFunc ;==>SHFileOperationErrDecode'; I'm curious what you think this is doing: RunWait(DirRemove("\\oldprofileserver\users\" & $sProfileName, 1)) RunWait(DirRemove("\\oldroamingprofile\profiles\" & $sProfileName, 1)) That takes the return value from DirRemove(), which is 0 or 1, and then tries to run the return value, i.e. RunWait(1) or RunWait(0). Is there a 0.exe or 1.bat there to be run? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
djsweaty Posted February 23, 2009 Author Share Posted February 23, 2009 The 1 is to recurse the entire directory and remove all files. It should not affect the run wait. DirRemove = 0 = (default) do not remove files and sub-directories 1 = remove files and subdirectories (like the DOS DelTree command) Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 23, 2009 Share Posted February 23, 2009 The 1 is to recurse the entire directory and remove all files. It should not affect the run wait.DirRemove = 0 = (default) do not remove files and sub-directories 1 = remove files and subdirectories (like the DOS DelTree command)Read my post again. It's not about the second parameter passed to DirRemove(). It's the fact that you are trying to execute a return value. You are going to get either 0 or 1 back as the return value from DirRemove(), and then you are trying to use RunWait() to execute the return value! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
djsweaty Posted February 23, 2009 Author Share Posted February 23, 2009 Read my post again. It's not about the second parameter passed to DirRemove(). It's the fact that you are trying to execute a return value. You are going to get either 0 or 1 back as the return value from DirRemove(), and then you are trying to use RunWait() to execute the return value! Now I see what you mean, I think. I was thinking incorrectly when using the RunWait to pause the script until the DirRemove was done before going to the next command. I was initially testing it's use and forgot to remove it as it was not needed. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now