unknownsoldierx Posted July 28, 2010 Posted July 28, 2010 I have this great script a user over at Neowin created for me. It works for him, but we can't figure out why it doesn't work for me. I have a folder on a remote machine shared as "Locked$". The script is supposed to mount a TrueCrypt volume as drive X on my local machine and run robocopy. But, it doesn't mount the volume. Also, the simple job I configured doesn't work. I have tried this on the command line without admin elevation and it works: C:\Windows\System32\robocopy.exe "D:\Patrick" \\DOWNSTAIRS\Patrick$ /mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h Here is the script with default variables: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/cs=1 /cn=1 /cf=1 /cv=1 /sf=1 /sv=1 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;includes #include <Array.au3> ; variables ;logfile, including path ; ;options ; 1 = Write mode (append to end of file) ; 2 = Write mode (erase previous contents) ; ;i.e. if you want to create a new log file each time, change the 1 to 2, or if you want to keep an ongoing log every time you run the script, leave it as 1 $Log = FileOpen("D:\True crypt\copylog.txt", 2) ;====TrueCrypt Settings ========= ;$TC_Exe - path to truecrypt executable $TC_Exe = "D:\True Crypt\TrueCrypt.exe" ;truecrypt container path $TC_Path = "D:\test" ; truecrypt driveletter assign $TC_DriveLetter = "x" ;truecrypt password $TC_Password = "test123" ;====Network Share Settings ========= ;$MapError - global variable used in _MapError function to give informative errors from a failed mapping. Leave it blank Global $MapError ; total number of jobs global $TotalNumberOfJobs ;NetworkDomain - name of domain that contains your user credentials, if on same machine, then you can use @ComputerName , no quotations marks around this, its an autoit macro. $NetworkDomain = @ComputerName ;NetworkUsername - your network username $NetworkUsername = "username" ;NetworkPassword - your network password $NetworkPassword = "password" ;====Robocopy Settings ========= ;$RC_Path - path to robocopy $RC_Path = "D:\True crypt\robocopy.exe" ;$RC_Ini - a file containing multiple source and destination folders ; this file will have a heading of [Copy] ; then under heading a separate number=robocopy options,source,destination on its own line for each copy job ; i.e.: ; ;[Copy] ;1=/e /copyall,c:\temp,d:\temp ;2=/mir,c:\windows,e:\windows $RC_Ini = "D:\True Crypt\Robocopy.ini" ;$RC_Log - path to where you want to store robocopy logs for each job. Log files are created automatically for each job in the naming format: job_X_robocopy.log, where X is the job number. $RC_Log = "D:\True Crypt\" ; script start ;test username and password, no point going through it all if it wont work If RunAs($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then ;write the success of user/pass to the console/logfile ConsoleWrite(@CRLF & "User Credentials: ACCEPTED" & @CRLF & "User Credentials: Username and/or Password recognised on: " & $NetworkDomain) FileWriteLine($Log, @CRLF & "User Credentials: ACCEPTED" & @CRLF & "User Credentials: Username and/or Password recognised on: " & $NetworkDomain) Else ;write the failure of user/pass to the console/logfile ConsoleWrite(@CRLF & "User Credentials: FAILED" & @CRLF & "User Credentials: Username and/or Password not recognised on: " & $NetworkDomain) FileWriteLine($Log, @CRLF & "User Credentials: FAILED" & @CRLF & "User Credentials: Username and/or Password not recognised on: " & $NetworkDomain) FileClose($Log) Exit EndIf ;Mount True Crypt Volume ConsoleWrite(@CRLF & @CRLF & "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....") FileWriteLine($Log, @CRLF & "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....") ConsoleWrite(@CRLF & "Using command line: " & Chr(34) & $TC_Exe & Chr(34) & " /q /v " & Chr(34) & $TC_Path & Chr(34) & " /l" & $TC_DriveLetter & " /p password") FileWriteLine($Log, "Using command line: " & Chr(34) & $TC_Exe & Chr(34) & " /q /v " & Chr(34) & $TC_Path & Chr(34) & " /l" & $TC_DriveLetter & " /p password") $TCMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) & $TC_Exe & Chr(34) & " /q /v " & Chr(34) & $TC_Path & Chr(34) & " /l" & $TC_DriveLetter & " /p " & $TC_Password) If NOT @error Or $TCMount = 0 Then ;write the success of truecrypt mounting to the console ConsoleWrite(@CRLF & "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....MOUNTED") ;write it to the logfile FileWriteLine($Log, "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....MOUNTED") Else ;write the failure of truecrypt mounting to the console/logfile ConsoleWrite(@CRLF & "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....FAILED" & @CRLF & "ExitCode: " & @error & "TrueCrypt returned error: " & $TCMount) FileWriteLine($Log, @CRLF & "Attempting to mount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....FAILED" & @CRLF & "ExitCode: " & @error & "TrueCrypt returned error: " & $TCMount) FileClose($Log) EndIf ;Robocopy stuff ConsoleWrite(@CRLF & @CRLF & "Attempting to open job list file: " & $RC_Ini & " ....") FileWriteLine($Log, @CRLF & "Attempting to open job list file: " & $RC_Ini & " ....") $CopyLines = IniReadSection($RC_Ini, "Copy") If @error Then ;if there's a problem with the ini file (like being missing) write it to the console/logfile ConsoleWrite(@CRLF & "Attempting to open job list file: " & $RC_Ini & " ....FAILED" & _ "Attempting to open job list file: " & $RC_Ini & " .... Error occurred, probably no INI file.") FileWriteLine($Log, "Attempting to open job list file: " & $RC_Ini & " ....FAILED" & _ "Attempting to open job list file: " & $RC_Ini & " .... Error occurred, probably no INI file.") Exit Else ConsoleWrite(@CRLF & "Attempting to open job list file: " & $RC_Ini & " ....SUCCESSFUL") FileWriteLine($Log, "Attempting to open job list file: " & $RC_Ini & " ....SUCCESSFUL") ;generate total number of jobs to be run, this is saved for the summary $TotalNumberOfJobs = $CopyLines[0][0] ;generate number of jobs to be run, this is saved for the summary as successful jobs run $NumberOfJobs = $CopyLines[0][0] ConsoleWrite(@CRLF & @CRLF & "Processing jobs....") FileWriteLine($Log, @CRLF & "Processing jobs....") For $i = 1 To $CopyLines[0][0] SetError(0) ;split value (containing ROBOCOPYOPTIONS,SOURCE,DESTINATION) into 3 separate variables at the comma $CopyLinesSplit = StringSplit($CopyLines[$i][1], ",") If $CopyLinesSplit[0] < 3 Then ;if there are not 3 values split by a comma then write error to the console and move to the next key/value pair Select Case $CopyLines[0][0] = 1 ;if theres only 1 job, then write job failed to console/logfile ConsoleWrite(@CRLF & "Job number: " & $i & " - Missing value in Ini File" & @CRLF & _ "Job number: " & $i & " - ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " - FAILED.") FileWriteLine($Log, @CRLF & "Job number: " & $i & " - Missing value in Ini File" & @CRLF & _ "Job number: " & $i & " - ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " - FAILED.") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case Else ;if there are more than 1 jobs, then write job failed to console/logfile and that we're skipping to next job ConsoleWrite(@CRLF & "Job number: " & $i & " - Missing value in Ini File" & @CRLF & _ "Job number: " & $i & " - ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Skipping to next job...") ;if there are not 3 values split by a comma then write error to the logfile and move to the next key/value pair FileWriteLine($Log, @CRLF & "Job number: " & $i & " - Missing value in Ini File" & @CRLF & _ "Job number: " & $i & " - ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Skipping to next job...") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 EndSelect Else ;check for empty element in returned array, this would mean you had put a comma after say source but failed to put in a value destination $CheckEmpty = _ArraySearch($CopyLinesSplit, "", 1) ;if a blank value is NOT found, continue script, in this case @error is actually good :) If @error Then ;set robocopy options variable from the first element of $CopyLinesSplit array $RC_Options = $CopyLinesSplit[1] ;set source variable from the second element of $CopyLinesSplit array $CopySource = $CopyLinesSplit[2] ;set destination from the third element of $CopyLinesSplit array $CopyDestination = $CopyLinesSplit[3] ConsoleWrite(@CRLF & @CRLF & "Job number: " & $i & " starting..." & @CRLF & _ "Job number: " & $i & " RoboCopy Options: " & $RC_Options & @CRLF & _ "Job number: " & $i & " Source Folder: " & Chr(34) & $CopySource & Chr(34) & @CRLF & _ "Job number: " & $i & " Destination Folder: " & Chr(34) & $CopyDestination & Chr(34)) FileWriteLine($Log, @CRLF & "Job number: " & $i & " starting..." & @CRLF & _ "Job number: " & $i & " RoboCopy Options: " & $RC_Options & @CRLF & _ "Job number: " & $i & " Source Folder: " & Chr(34) & $CopySource & Chr(34) & @CRLF & _ "Job number: " & $i & " Destination Folder: " & Chr(34) & $CopyDestination & Chr(34)) ;check source folder exists ConsoleWrite(@CRLF & "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....") FileWriteLine($Log, "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....") $CheckSourceFolder = FileExists($CopySource) If $CheckSourceFolder = 0 Then ConsoleWrite(@CRLF & "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....FAILED") FileWriteLine($Log, "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....FAILED") ;skip to next job ContinueLoop Else ConsoleWrite(@CRLF & "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....SUCCESS") FileWriteLine($Log, "Job number: " & $i & " Checking source folder: " & Chr(34) & $CopySource & Chr(34) & " exists....SUCCESS") EndIf ;get the pure letter of the drive to check against the truecrypt mounted drive letter for the current job ;if its the same, we already know it exists and we skip the next part of the drive check. If we dont check ;for a match here and the truyecrypt drive letter makes it into the next check it will FAIL as even though ;the truecrypt drive is mounted, it will report UNKNOWN to DriveStatus. This "error" is because TrueCrypt is a container, not a real drive. $CheckDestinationFolder = StringLeft($CopyDestination, 1) ;check destination drive exists - no point always testing if folder exists as the job may be creating a folder ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....") If $CheckDestinationFolder <> $TC_DriveLetter Then $CheckDestinationFolder2 = DriveStatus(StringLeft($CopyDestination, 3)) Select Case "UNKNOWN" ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....FAILED: UNKNOWN" & _ @CRLF & "ERROR returned message - UKNOWN - Drive may be unformatted (RAW).") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....FAILED: UNKNOWN" & _ @CRLF & "Drive may be unformatted (RAW).") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 ;skip to next job ContinueLoop Case "READY" ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....SUCCESS: DRIVE READY") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....SUCCESS: DRIVE READY") Case "INVALID" ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder &" exists and is accessible....FAILED: INVALID" & _ @CRLF & "ERROR returned message - INVALID - May indicate the drive letter does not exist or that a mapped network drive is inaccessible.") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....FAILED: INVALID" & _ @CRLF & "ERROR returned message - INVALID - May indicate the drive letter does not exist or that a mapped network drive is inaccessible.") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 ;skip to next job ContinueLoop Case "UNKNOWN" ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....FAILED: UKNOWN" & _ @CRLF & "ERROR returned message - INVALID - Drive may be unformatted (RAW).") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....FAILED: UKNOWN" & _ @CRLF & "ERROR returned message - INVALID - Drive may be unformatted (RAW).") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 ;skip to next job ContinueLoop EndSelect Else ;write truecrypt container as destination to console/logfile ConsoleWrite(@CRLF & "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....SUCCESS: DRIVE READY (Using TrueCrypt Container)") FileWriteLine($Log, "Job number: " & $i & " Checking destination drive: " & $CheckDestinationFolder & " exists and is accessible....SUCCESS: DRIVE READY (Using TrueCrypt Container)") EndIf ;do the actual copying $RoboCopy = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) & $RC_Path & Chr(34) & " " & $RC_Options & " " & "/LOG+:" & Chr(34) & $RC_Log & "Job_" & $i & "_robocopy.log" & Chr(34) & " " & Chr(34) & $CopySource & Chr(34) & " " & Chr(34) & $CopyDestination& Chr(34)) ;Write copy result to console Switch @error Case 0 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: NO CHANGE **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: NO CHANGE **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 1 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: COPY **** SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: COPY **** SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 2 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 3 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 4 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: MISM **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: MISM **** SUCPARTIAL CESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 5 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: MISM COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: MISM COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 6 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: MISM XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: MISM XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 7 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: MISM XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: MISM XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO") Case 8 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 9 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 10 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 11 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 12 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL MISM **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL MISM **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 13 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL MISM COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL MISM COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 14 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: AIL MISM XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: AIL MISM XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 15 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: FAIL MISM XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: FAIL MISM XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case 16 ConsoleWrite(@CRLF & "Job number: " & $i & " ROBOCOPY reports: **** FATAL ERROR **** - CHECK ROBOCOPY LOG OR FURTHER INFO") FileWriteLine($Log, "Job number: " & $i & " ROBOCOPY reports: ****FATAL ERROR **** - CHECK ROBOCOPY LOG OR FURTHER INFO") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 EndSwitch Else ;if a blank value is found anywhere in $CopyLinesSplit array (i.e. you had a line such as "1=/mir,c:\windows," - missing destination but still a comma after source), ;then of course robocopy will fail, write error to console/logfile, then skip to next job Select Case $CopyLines[0][0] = 1 ;if theres only 1 job, then write job failed to console/logfile ConsoleWrite(@CRLF & "Job number: " & $i & " **** Blank value in Ini File *****" & @CRLF & _ "Job number: " & $i & " ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " **** FAILURE - CHECK INI FILE ****") FileWriteLine($Log, @CRLF & "Job number: " & $i & " **** Blank value in Ini File *****" & @CRLF & _ "Job number: " & $i & " ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " **** FAILURE - CHECK INI FILE ****") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 Case Else ;if there are more than 1 jobs, then write job failed to console/logfile and that we're skipping to next job ConsoleWrite(@CRLF & "Job number: " & $i & " **** Blank value in Ini File *****" & @CRLF & _ "Job number: " & $i & " ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " **** FAILURE - CHECK INI FILE ****" & @CRLF & _ "Skipping to next job...") ;if there are not 3 values split by a comma then write error to the logfile and move to the next key/value pair FileWriteLine($Log, @CRLF & "Job number: " & $i & " **** Blank value in Ini File *****" & @CRLF & _ "Job number: " & $i & " ERROR: expecting Robocopy Options, Source, Destination. One is missing" & @CRLF & _ "Job number: " & $i & " **** FAILURE - CHECK INI FILE ****" & @CRLF & _ "Skipping to next job...") ;decrease the amount of successful jobs by 1 $NumberOfJobs -= 1 EndSelect EndIf EndIf Next EndIf ;write total number of jobs to console/logfile ConsoleWrite(@CRLF & @CRLF & $TotalNumberOfJobs & " total jobs submitted for processing") FileWriteLine($Log, @CRLF & $TotalNumberOfJobs & " total jobs submitted for processing") ;write the number of successful jobs to console/logfile ConsoleWrite(@CRLF & $NumberOfJobs & " of " & $CopyLines[0][0] & " jobs completed successfully") FileWriteLine($Log, $NumberOfJobs & " of " & $CopyLines[0][0] & " jobs completed successfully") ;whack in a quick 2 second sleep Sleep(2000) ;Un-Mount True Crypt Volume ConsoleWrite(@CRLF & @CRLF & "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....") FileWriteLine($Log, @CRLF & "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....") $TCUnMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) & $TC_Exe & Chr(34) & " /q /d " & $TC_DriveLetter) If @error Or $TCUnMount > 0 Then ;write the failure of truecrypt unmounting to the console/logfile ConsoleWrite(@CRLF & "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....FAILED" & @CRLF & "ExitCode: " & @error & "TrueCrypt returned error: " & $TCUnMount) FileWriteLine($Log, "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....FAILED" & @CRLF & "ExitCode: " & @error & "TrueCrypt returned error: " & $TCUnMount) EndIf ;write the success of truecrypt unmounting to the console/logfile ConsoleWrite(@CRLF & "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....UNMOUNTED") FileWriteLine($Log, "Attempting to unmount truecrypt volume: " & Chr(34) & $TC_Path & Chr(34) & " on drive letter: " & $TC_DriveLetter & " ....UNMOUNTED") FileClose($Log) Exit ;close the log file FileClose($Log) ; this just converts numerical drive mapping $error codes to english :) ;moving this to a function which is called twice just means not having this all added twice in the main script... Func _MapError($error) Switch $error Case 1 $MapError = "Undefined / Other error" Case 2 $MapError = "Access to the remote share was denied" Case 3 $MapError = "The device is already assigned" Case 4 $MapError = "Invalid device name" Case 5 $MapError = "Invalid remote share" Case 6 $MapError = "Invalid password" EndSwitch return $MapError EndFunc Here is my simple test robocopy.ini: [Copy] 1=/mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$ Here is the log it produces: User Credentials: ACCEPTED User Credentials: Username and/or Password recognised on: UPSTAIRS Attempting to mount truecrypt volume: "\\DOWNSTAIRS\Locked$\backups" on drive letter: x .... Using command line: "C:\Program Files\TeraCopy\TrueCrypt.exe" /q /v "\\DOWNSTAIRS\Locked$\backups" /lx /p password Attempting to mount truecrypt volume: "\\DOWNSTAIRS\Locked$\backups" on drive letter: x ....MOUNTED Attempting to open job list file: D:\Programs\backups\robocopy.ini .... Attempting to open job list file: D:\Programs\backups\robocopy.ini ....SUCCESSFUL Processing jobs.... Job number: 1 starting... Job number: 1 RoboCopy Options: /mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h Job number: 1 Source Folder: "D:\Patrick" Job number: 1 Destination Folder: "\\DOWNSTAIRS\Patrick$" Job number: 1 Checking source folder: "D:\Patrick" exists.... Job number: 1 Checking source folder: "D:\Patrick" exists....SUCCESS Job number: 1 Checking destination drive: \ exists and is accessible.... Job number: 1 Checking destination drive: \ exists and is accessible....FAILED: UNKNOWN Drive may be unformatted (RAW). 1 total jobs submitted for processing 0 of 1 jobs completed successfully Attempting to unmount truecrypt volume: "\\DOWNSTAIRS\Locked$\backups" on drive letter: x .... Attempting to unmount truecrypt volume: "\\DOWNSTAIRS\Locked$\backups" on drive letter: x ....FAILED ExitCode: 0TrueCrypt returned error: 0 Attempting to unmount truecrypt volume: "\\DOWNSTAIRS\Locked$\backups" on drive letter: x ....UNMOUNTED
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