Secure use of passwords in batch files?


Recommended Posts

Updated....

Added:

* user credentials test, halts script if you fail, seemed a reasonable and useful thing to add, no point the rest of the script running is your username/password is wrong

* multiple robocopy job support, with individual logs for each job, i.e. job_1_robocopy.lo, job_2_robocopy.log

- the reason for these is because the exit codes from robocopy are largely, as far as i have seen, erroneous and even copying files to a destination that you havent before returns exit code 0 which according to the microsoft robocopy exit codes is no files copied, directories synchronised or according to their table in short format (NO CHANGE), when it should be exit code 1 - (COPY SUCCESSFUL). Dont blame me im just using thier info. But i thought id add the ability to log robocopys detailed logs on a per job basis automatically, so you can check in detail. All robocopy exit codes and errors are Microsofts, i just copied and pasted and put the short form in brackets () as a guide. I suggest always checking the individual jobs robocopy logs....

* more error checking generally

* logging to both console and log file

As always i have no network to test the drive mapping on, but the rest of the script is pretty well tested...

Heres some output demos for you, one form when i left a required value out of the ini file and th other when i put it back in

Theres an endless amount of error checking you can do in scripts, ive just covered the more obvious ones, like accidentally leaving out a value in the ini file

If you really want extra error checking like source and destination path checking before a copy, i will kill you, but ill do it....

This is a log from an ini file with a missing job value

[Copy]
1=/e /copyall,
2=/mir,d:\temp,z:\test2

logfile/console output:

User Credentails:  ACCEPTED
User Credentails:  Username and/or Password recognised on:  DESKTOP

Attempting to mount truecrypt volume:  D:\test  on drive letter:  z ....

Successfully mounted:  D:\test to Drive:  z

Job number:  1  - Missing value in Ini File
Job number:  1  - ERROR: expecting Robocopy Options, Source, Destination. One is missing
Skipping to next job...

Job number:  2  starting...
Job number:  2  RoboCopy Options:  /mir
Job number:  2  Source Folder:  d:\temp
Job number:  2  Destination Folder:  z:\test2
Job number:  2  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  2  According to MS error code 0 means at least a partial robocopy success
Job number:  2  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****

1  of  2  jobs completed successfully

Successfully unmounted:  D:\test from Drive:  z

This is from a correct job ini file

[Copy]
1=/e /copyall,d:\temp,z:\test
2=/mir,d:\temp,z:\test2

logfile/console output:

User Credentails:  ACCEPTED
User Credentails:  Username and/or Password recognised on:  DESKTOP

Attempting to mount truecrypt volume:  D:\test  on drive letter:  z ....

Successfully mounted:  D:\test to Drive:  z

Job number:  1  starting...
Job number:  1  RoboCopy Options:  /e /copyall
Job number:  1  Source Folder:  d:\temp
Job number:  1  Destination Folder:  z:\test
Job number:  1  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  1  According to MS error code 0 means at least a partial robocopy success
Job number:  1  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****

Job number:  2  starting...
Job number:  2  RoboCopy Options:  /mir
Job number:  2  Source Folder:  d:\temp
Job number:  2  Destination Folder:  z:\test2
Job number:  2  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  2  According to MS error code 0 means at least a partial robocopy success
Job number:  2  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****

2  of  2  jobs completed successfully

Successfully unmounted:  D:\test from Drive:  z

Full script:

#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:\Truecrypt\copylog.txt", 1)


;====TrueCrypt Settings =========
;$TC_Exe - path to truecrypt executable
$TC_Exe = "D:\TrueCrypt\TrueCrypt.exe"
;truecrypt container path
$TC_Path = "D:\test"
; truecrypt driveletter assign
$TC_DriveLetter = "z"
;truecrypt password
$TC_Password =  "test123"

;====Network Share Settings =========
;MapDriveMachineName - name of machine that has drive you wish to map, if on same machine, then you can use @ComputerName , no quotations marks around this, its an autoit macro.
$MapDriveMachineName = @ComputerName
;MapDrivePath1 - the 1st path on the machine you wish to share
$MapDrivePath1 = "\path"
;MapDrivePath2 - the 2nd path on the machine you wish to share
$MapDrivePath2 = "\path"
;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:\Truecrypt\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=roboopy 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:\TrueCrypt\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:\TrueCrypt\"




; 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 Credentails:  ACCEPTED" & @CRLF & "User Credentails:  Username and/or Password recognised on:  " & $NetworkDomain)
	FileWriteLine($Log, @CRLF & "User Credentails:  ACCEPTED" & @CRLF & "User Credentails:  Username and/or Password recognised on:  " & $NetworkDomain)
Else
    ;write the failure of user/pass to the console/logfile
	ConsoleWrite(@CRLF & "User Credentails:  FAILED" & @CRLF & "User Credentails:  Username and/or Password not recognised on:  " & $NetworkDomain)
	FileWriteLine($Log, @CRLF & "User Credentails:  FAILED" & @CRLF & "User Credentails:  Username and/or Password not recognised on:  " & $NetworkDomain)
	FileClose($Log)
Exit
EndIf


;Mount True Crypt Volume
FileWriteLine($Log, @CRLF & "Attempting to mount truecrypt volume:  " & $TC_Path & "  on drive letter:  " & $TC_DriveLetter & " ....")
$TCMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe & " /q /v " & $TC_Path & " /l" & $TC_DriveLetter & " /p " & $TC_Password)

If NOT @error Or $TCMount = 0 Then

	;write the success of truecrypt mounting to the console
	ConsoleWrite(@CRLF & "Successfully mounted:  " & $TC_Path & " to Drive:  " & $TC_DriveLetter)
	;write it to the logfile
	FileWriteLine($Log, @CRLF & "Successfully mounted:  " & $TC_Path & " to Drive:  " & $TC_DriveLetter)

	; Map drives
	$Map1_Add = DriveMapAdd("y:", "\\" & $MapDriveMachineName & "\" & $MapDrivePath1, 0, $NetworkDomain & "\" & $NetworkUsername, $NetworkPassword)
	If $Map1_Add = 1 Then
		;write the success of drive mapping to the console
		ConsoleWrite(@CRLF & "Successfully mapped network drive:  " & $MapDrivePath1)
		;write the success of drive mapping to the logfile
		FileWriteLine($Log, @CRLF & "Successfully mapped network drive:  " & $MapDrivePath1)
		SetError(0)
	Else
		;write the failure of drive mapping to the console
		ConsoleWrite(@CRLF & "Failed to map network drive:  " & $MapDrivePath1  & " the error returned is:  " & @extended)
		;write the failure of drive mapping to the logfile
		FileWriteLine($Log, @CRLF & "Failed to map network drive:  " & $MapDrivePath1  & " the error returned is:  " & @extended)
		FileClose($Log)
		Exit
	EndIf

	$Map2_Add = DriveMapAdd("z:", "\\" & $MapDriveMachineName & "\" & $MapDrivePath2, 0, $NetworkDomain & "\" & $NetworkUsername, $NetworkPassword)
	If $Map2_Add = 1 Then
		;write the success of drive mapping to the console
		ConsoleWrite(@CRLF & "Successfully mapped network drive:  " & $MapDrivePath2)
		;write the success of drive mapping to the logfile
		FileWriteLine($Log, @CRLF & "Successfully mapped network drive:  " & $MapDrivePath2)
		SetError(0)
	Else
		;write the failure of drive mapping to the console
		ConsoleWrite(@CRLF & "Failed to map network drive:  " & $MapDrivePath2  & " the error returned is:  " & @extended)
		;write the failure of drive mapping to the logfile
		FileWriteLine($Log, @CRLF & "Failed to map network drive:  " & $MapDrivePath2  & " the error returned is:  " & @extended)
		FileClose($Log)
		Exit
	EndIf

	;Robocopy stuff
	$CopyLines = IniReadSection($RC_Ini, "Copy")
	If @error Then
		;MsgBox(4096, "", "Error occurred, probably no INI file.")
		ConsoleWrite(@CRLF & "Failed to open Ini file:  " & $RC_Ini & " Error occurred, probably no INI file.")
		FileWriteLine($Log, @CRLF & "Failed to open Ini file:  " & $RC_Ini & " Error occurred, probably no INI file.")
		Exit
	Else
		$NumberOfJobs = $CopyLines[0][0]
		For $i = 1 To $CopyLines[0][0]

		;split value (containing ROBOCOPYOPTIONS,SOURCE,DESTINATION) into 3 seperate 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.")
				$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...")
				$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 & "Job number:  " & $i &  "  starting..." &  @CRLF & _
		"Job number:  " & $i &  "  RoboCopy Options:  " & $RC_Options & @CRLF & _
		"Job number:  " & $i &  "  Source Folder:  " & $CopySource & @CRLF & _
		"Job number:  " & $i &  "  Destination Folder:  " & $CopyDestination)
		FileWriteLine($Log, @CRLF & "Job number:  " & $i &  "  starting..." &  @CRLF & _
		"Job number:  " & $i &  "  RoboCopy Options:  " & $RC_Options & @CRLF & _
		"Job number:  " & $i &  "  Source Folder:  " & $CopySource & @CRLF & _
		"Job number:  " & $i &  "  Destination Folder:  " & $CopyDestination)
		$RoboCopy = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $RC_Path & " " & $RC_Options & " " & "/LOG+:" & $RC_Log & "Job_" & $i & "_robocopy.log" & " " & $CopySource & " " & $CopyDestination)
		;Write copy result to console
		Switch @error
			Case 0
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 0 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 0 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
			Case 1
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  One or more files were copied successfully (that is, new files have arrived." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 1 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  One or more files were copied successfully (that is, new files have arrived." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 1 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
			Case 2
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 2 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 2 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
			Case 4
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 4 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 4 means at least a partial robocopy success" & @CRLF & "Job number:  " & $i & "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
			;According to MS any error code greater than 8 means a possible robocopy failure
			 Case 8
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 8 means at least a partial robocopy failure" & @CRLF & "Job number:  " & $i & "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 8 means at least a partial robocopy failure" & @CRLF & "Job number:  " & $i & "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
				$NumberOfJobs -= 1
			;According to MS error code 16 means a robocopy failure
			 Case 16
				ConsoleWrite(@CRLF & "Job number:  " & $i & "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" & @CRLF & _
				"Job number:  " & $i & "  to insufficient access privileges on the source or destination directories." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 16 means a robocopy failure" & @CRLF & "Job number:  " & $i & "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " & $i & "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" & @CRLF & _
				"Job number:  " & $i & "  to insufficient access privileges on the source or destination directories." & @CRLF & _
				"Job number:  " & $i & "  According to MS error code 16 means a robocopy failure" & @CRLF & "Job number:  " & $i & "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
				$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 ****")
					$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...")
					$NumberOfJobs -= 1
			EndSelect

		EndIf
	EndIf
	Next
	EndIf


;write the number of successful jobs to console/logfile
ConsoleWrite(@CRLF & $NumberOfJobs & "  of  " & $CopyLines[0][0] & "  jobs completed successfully")
FileWriteLine($Log, @CRLF & $NumberOfJobs & "  of  " & $CopyLines[0][0] & "  jobs completed successfully")



	;whack in a quick 2 second sleep
	Sleep(2000)

    ;UnMap Drives
	$Map1_Del = DriveMapDel("y:")
	If $Map1_Del = 1 Then
		;write the success of drive unmapping to the console
		ConsoleWrite(@CRLF & "Successfully unmapped network drive:  " & $MapDrivePath1)
		;write the success of drive unmapping to the logfile
		FileWriteLine($Log, @CRLF & "Successfully unmapped network drive:  " & $MapDrivePath1)
		SetError(0)
	Else
		;write the failure of drive unmapping to the console
		ConsoleWrite(@CRLF & "Failed to unmap network drive:  " & $MapDrivePath1  & " the error returned is:  " & @extended)
		;write the failure of drive unmapping to the logfile
		FileWriteLine($Log, @CRLF & "Failed to unmap network drive:  " & $MapDrivePath1  & " the error returned is:  " & @extended)
		FileClose($Log)
		Exit
	EndIf
	$Map2_Del = DriveMapDel("z:")
	If $Map2_Del = 1 Then
		;write the success of drive unmapping to the console
		ConsoleWrite(@CRLF & "Successfully unmapped network drive:  " & $MapDrivePath2)
		;write the success of drive unmapping to the logfile
		FileWriteLine($Log, @CRLF & "Successfully unmapped network drive:  " & $MapDrivePath2)
		SetError(0)
	Else
		;write the failure of drive unmapping to the console
		ConsoleWrite(@CRLF & "Failed to unmap network drive:  " & $MapDrivePath2  & " the error returned is:  " & @extended)
		;write the failure of drive unmapping to the logfile
		FileWriteLine($Log, @CRLF & "Failed to unmap network drive:  " & $MapDrivePath2  & " the error returned is:  " & @extended)
		FileClose($Log)
		Exit
	EndIf


	;Un-Mount True Crypt Volume
	$TCUnMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe & " /q /d " & $TC_DriveLetter)
	If @error Or $TCUnMount > 0 Then
		;write the failure of truecrypt unmounting to the console
		ConsoleWrite(@CRLF & "Failed to unmount:  " & $TC_Path & " from Drive:  " & $TC_DriveLetter & @CRLF  & "ExitCode:  " & @error & "TrueCrypt returned error:  " & $TCUnMount)
		;write the failure of truecrypt unmounting to the logfile
		FileWriteLine($Log, @CRLF & "Failed to unmount:  " & $TC_Path & " from Drive:  " & $TC_DriveLetter & @CRLF  & "ExitCode:  " & @error & "TrueCrypt returned error:  " & $TCUnMount)
	EndIf
	;write the success of truecrypt unmounting to the console
	ConsoleWrite(@CRLF & "Successfully unmounted:  " & $TC_Path & " from Drive:  " & $TC_DriveLetter)
	;write the success of truecrypt unmounting to the logile
	FileWriteLine($Log, @CRLF & "Successfully unmounted:  " & $TC_Path & " from Drive:  " & $TC_DriveLetter)
	FileClose($Log)
	Exit

Else
	;write the failure of truecrypt mounting to the console
	ConsoleWrite(@CRLF & "Failed to mount:  " & $TC_Path & " to Drive:  " & $TC_DriveLetter & @CRLF  & "ExitCode:  " & @error & "TrueCrypt returned error:  " & $TCMount)
	;write the failure of truecrypt mounting to the logfile
	FileWriteLine($Log, @CRLF & "Failed to mount:  " & $TC_Path & " to Drive:  " & $TC_DriveLetter & @CRLF  & "ExitCode:  " & @error & "TrueCrypt returned error:  " & $TCMount)
	FileClose($Log)
EndIf




;close the log file
FileClose($Log)

Link to comment
Share on other sites

This produced an error:

$NetworkDomain = @ComputerName

I changed it to this and the error went away:

$NetworkDomain = "@ComputerName"

I run the script and I get this:

User Credentails:  ACCEPTED
User Credentails:  Username and/or Password recognised on:  @DOWNSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\Backups to Drive:  z
Failed to map network drive:  \unknownsoldierx$ the error returned is:  53>Exit code: 0    Time: 2.645

I wasn't sure if I had to use the name of my machine or the name of the remote machine for the @computername, but I tried both. Also, the drive is not mounted, yet it reports success.

Link to comment
Share on other sites

This produced an error:

$NetworkDomain = @ComputerName

I changed it to this and the error went away:

$NetworkDomain = "@ComputerName"

I run the script and I get this:

User Credentails:  ACCEPTED
User Credentails:  Username and/or Password recognised on:  @DOWNSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\Backups to Drive:  z
Failed to map network drive:  \unknownsoldierx$ the error returned is:  53>Exit code: 0    Time: 2.645

I wasn't sure if I had to use the name of my machine or the name of the remote machine for the @computername, but I tried both. Also, the drive is not mounted, yet it reports success.

$MapDriveMachineName needs to be set to the name of the machine with the shares on it

If its not the same computer, it cant be @ComputerName, you have to specify it, and not with an @ in front of it, just the name in between quotations marks...

$NetworkDomain needs to be the name of the domain, or computer which you have the rights for the username and password youre using

It should be @ComputerName not "@ComputerName" unless you specify a computer name or domain name, and not with an @ in front of it, just the name in between quotations marks...

@ComputerName is an autoit macro for the same name you see in your system control panel info under computer name, full computer name

The " 's will kill its functionality

I used @ComputerName here in testing, it works fine

Why are there $'s in your drive paths: Locked$ and unknownsoldier$ ?

The only time you use a $ on the end of the drive is for admin shares, if your username and password has admin rights, you do not need to add these

PM or post me the variables section you are using (minus your username and password)

As for the drive not mapping but reporting success, if i dont supply a valid admin username and password, the script wont even get passed the credentials check, certainly not drive mapping

i removed 1 character form my password and this is all i get in the log:

User Credentails:  FAILED
User Credentails:  Username and/or Password not recognised on:  DESKTOP

So im not sure what youre doing :)

Link to comment
Share on other sites

$MapDriveMachineName needs to be set to the name of the machine with the shares on it

If its not the same computer, it cant be @ComputerName, you have to specify it

$NetworkDomain needs to be the name of the domain, or computer which you have the rights for the username and password youre using

It should be @ComputerName not "@ComputerName" unless you specify a computer name or domain name

@ComputerName is an autoit macro for the same name you see in your system control panel info under computer name, full computer name

The " 's will kill its functionality

I used @ComputerName here in testing, it works fine

I thought I had to change it. So I changed it to @Downstairs, which is the remote machine. But that gave me the error, so I changed it to "@Upstairs" and it worked.

But, since I have the same username and password on both machines, I just leave it as @ComputerName, right?

Why are there $'s in your drive paths: Locked$ and unknownsoldier$ ?

The only time you use a $ on the end of the drive is for admin shares, if your username and password has admin rights, you do not need to add these

I do that so they aren't visible on the network. Technically, only the default shares (c$, d$, etc.) are called admin shares. Any others are called hidden shares.

PM or post me the variables section you are using (minus your username and password)

Ok.

Link to comment
Share on other sites

working on the drive mapping error now

and working fine for me...

i realised i could map a drive on my local pc if i shared a folder first of course, so i can test the networking side of things

the only way i got it to fail mapping the drive was if the drive was already mapped...

ill adjust the error checking to test for already mapped drives...

Link to comment
Share on other sites

eeek found the problem,

1) drive letter overlap, how i missed that is beyond me, did i mention chronic lack of sleep?

truecrypt drive was set as z

share1 was y

share2 was z <--theres your problem

so i now have changed the letters to x and y....

$Map1_Add = DriveMapAdd("x:",
$Map2_Add = DriveMapAdd("y:",

Also there was an unneeded \ in the script that was messing the network path...slashes in autoit, i remember now, sometimes you have to add them to paths, sometimes not....this was a not time :)

Anyways just testing a bit but so far havent had a fail with mapping added on my machine

Corrected script coming soon

Link to comment
Share on other sites

Okay, as fixed as its gonna get i feel

As mentioned above i had to move the mapped drive letters around to x and y, so if you have the mapped drive letters in the inifile anywhere, youll need to update them accordingly

1 new variable:

;$MapError - global variable used in _MapError function to give informative errors from a failed mapping. Leave it blank
Global $MapError

This was created to allow converting the numerical error code from drive mapping to an actual error you can understand.

I created a function (_MapError) to do this and the variable it returns needs to exist before the function is called

Sorry, but you'll have to cut&paste the other variables from your existing script into this one :(

My apologies for so many revisions, this used to be childs play to me at one point (i have a script here thats about 4,000 lines long (and way more impressive and technically difficult than this one by about a million times) that i wrote about 3 or 4 years back when i was able to find a single error at a glance in those 4,000 lines), but i was on a lot of medication for the past year and a bit and its all a bit foggy, that part of my brain :)

Let me know if you want any further stuff done, i.e. moving the currently hardcoded mapped drive letters moved to the ini file, the ini file can drive those (and other stuff of course as well) too. I tend to just do quick and dirty and as needed scripts these days.

#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 &lt;Array.au3&gt;

; 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:\Truecrypt\copylog.txt", 1)


;====TrueCrypt Settings =========
;$TC_Exe - path to truecrypt executable
$TC_Exe = "D:\TrueCrypt\TrueCrypt.exe"
;truecrypt container path
$TC_Path = "D:\test"
; truecrypt driveletter assign
$TC_DriveLetter = "z"
;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

;MapDriveMachineName - name of machine that has drive you wish to map, if on same machine, then you can use @ComputerName , no quotations marks around this, its an autoit macro.
$MapDriveMachineName = @ComputerName
;MapDrivePath1 - the 1st path on the machine you wish to share
$MapDrivePath1 = "\Windows\Boot"
;MapDrivePath2 - the 2nd path on the machine you wish to share
$MapDrivePath2 = "\swap$"
;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:\Truecrypt\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:\TrueCrypt\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:\TrueCrypt\"




; script start


;test username and password, no point going through it all if it wont work
If RunAs($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, @ComSpec &amp; " /c VER", @WorkingDir, @SW_HIDE) Then
    ;write the success of user/pass to the console/logfile
	ConsoleWrite(@CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
	FileWriteLine($Log, @CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
Else
    ;write the failure of user/pass to the console/logfile
	ConsoleWrite(@CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
	FileWriteLine($Log, @CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
	FileClose($Log)
Exit
EndIf


;Mount True Crypt Volume
FileWriteLine($Log, @CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; $TC_Path &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
$TCMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe &amp; " /q /v " &amp; $TC_Path &amp; " /l" &amp; $TC_DriveLetter &amp; " /p " &amp; $TC_Password)

If NOT @error Or $TCMount = 0 Then

	;write the success of truecrypt mounting to the console
	ConsoleWrite(@CRLF &amp; "Successfully mounted:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter)
	;write it to the logfile
	FileWriteLine($Log, @CRLF &amp; "Successfully mounted:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter)

	; Map drives
	$Map1_Add = DriveMapAdd("x:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath1, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
	If $Map1_Add = 1 Then
		;write the success of drive mapping to the console
		ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
		;write the success of drive mapping to the logfile
		FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
		SetError(0)
	Else
		;send @error to function  _MapError to give non-numerical explanation :)
		_MapError(@error)
		;write the failure of drive mapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
		FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
		FileClose($Log)
		Exit
	EndIf

	$Map2_Add = DriveMapAdd("y:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath2, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
	If $Map2_Add = 1 Then
		;write the success of drive mapping to the console
		ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
		;write the success of drive mapping to the logfile
		FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
		SetError(0)
	Else
		;send @error to function  _MapError to give non-numerical explanation :)
		_MapError(@error)
		;write the failure of drive mapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath2  &amp; "  the error returned is:  " &amp; @error)
		FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath2  &amp; " the error returned is:  " &amp; @error)
		FileClose($Log)
		Exit
	EndIf

	;Robocopy stuff
	$CopyLines = IniReadSection($RC_Ini, "Copy")
	If @error Then
		;MsgBox(4096, "", "Error occurred, probably no INI file.")

		;if there's a problem with the ini file (like being missing) write it to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to open Ini file:  " &amp; $RC_Ini &amp; " Error occurred, probably no INI file.")
		FileWriteLine($Log, @CRLF &amp; "Failed to open Ini file:  " &amp; $RC_Ini &amp; " Error occurred, probably no INI file.")
		Exit
	Else
		$NumberOfJobs = $CopyLines[0][0]
		For $i = 1 To $CopyLines[0][0]

		;split value (containing ROBOCOPYOPTIONS,SOURCE,DESTINATION) into 3 separate variables at the comma
		$CopyLinesSplit = StringSplit($CopyLines[$i][1], ",")
		If $CopyLinesSplit[0] &lt; 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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - FAILED.")
				FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - FAILED.")
				$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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
				"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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
				"Skipping to next job...")
				$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 &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; $CopySource &amp; @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; $CopyDestination)
		FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; $CopySource &amp; @CRLF &amp; _
		"Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; $CopyDestination)
		$RoboCopy = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $RC_Path &amp; " " &amp; $RC_Options &amp; " " &amp; "/LOG+:" &amp; $RC_Log &amp; "Job_" &amp; $i &amp; "_robocopy.log" &amp; " " &amp; $CopySource &amp; " " &amp; $CopyDestination)
		;Write copy result to console
		Switch @error
			Case 0
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 0 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 0 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
			Case 1
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  One or more files were copied successfully (that is, new files have arrived." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 1 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  One or more files were copied successfully (that is, new files have arrived." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 1 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
			Case 2
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 2 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 2 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
			Case 4
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 4 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 4 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
			;According to MS any error code greater than 8 means a possible robocopy failure
			 Case 8
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 8 means at least a partial robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 8 means at least a partial robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
				$NumberOfJobs -= 1
			;According to MS error code 16 means a robocopy failure
			 Case 16
				ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  to insufficient access privileges on the source or destination directories." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 16 means a robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
				FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  to insufficient access privileges on the source or destination directories." &amp; @CRLF &amp; _
				"Job number:  " &amp; $i &amp; "  According to MS error code 16 means a robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
				$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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****")
					FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****")
					$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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
					"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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
					"Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
					"Skipping to next job...")
					$NumberOfJobs -= 1
			EndSelect

		EndIf
	EndIf
	Next
	EndIf


;write the number of successful jobs to console/logfile
ConsoleWrite(@CRLF &amp; $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")
FileWriteLine($Log, @CRLF &amp; $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")



	;whack in a quick 2 second sleep
	Sleep(2000)

    ;UnMap Drives
	$Map1_Del = DriveMapDel("x:")
	If $Map1_Del = 1 Then
		;write the success of drive unmapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Successfully unmapped network drive:  " &amp; $MapDrivePath1)
		FileWriteLine($Log, @CRLF &amp; "Successfully unmapped network drive:  " &amp; $MapDrivePath1)
		SetError(0)
	Else
		;write the failure of drive unmapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to unmap network drive:  " &amp; $MapDrivePath1  &amp; " the error returned is:  " &amp; @error)
		FileWriteLine($Log, @CRLF &amp; "Failed to unmap network drive:  " &amp; $MapDrivePath1  &amp; " the error returned is:  " &amp; @error)
		FileClose($Log)
		Exit
	EndIf
	$Map2_Del = DriveMapDel("y:")
	If $Map2_Del = 1 Then
		;write the success of drive unmapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Successfully unmapped network drive:  " &amp; $MapDrivePath2)
		FileWriteLine($Log, @CRLF &amp; "Successfully unmapped network drive:  " &amp; $MapDrivePath2)
		SetError(0)
	Else
		;write the failure of drive unmapping to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to unmap network drive:  " &amp; $MapDrivePath2  &amp; " the error returned is:  " &amp; @error)
		FileWriteLine($Log, @CRLF &amp; "Failed to unmap network drive:  " &amp; $MapDrivePath2  &amp; " the error returned is:  " &amp; @error)
		FileClose($Log)
		Exit
	EndIf


	;Un-Mount True Crypt Volume
	$TCUnMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe &amp; " /q /d " &amp; $TC_DriveLetter)
	If @error Or $TCUnMount &gt; 0 Then
		;write the failure of truecrypt unmounting to the console/logfile
		ConsoleWrite(@CRLF &amp; "Failed to unmount:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
		FileWriteLine($Log, @CRLF &amp; "Failed to unmount:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
	EndIf
	;write the success of truecrypt unmounting to the console/logfile
	ConsoleWrite(@CRLF &amp; "Successfully unmounted:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter)
	FileWriteLine($Log, @CRLF &amp; "Successfully unmounted:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter)
	FileClose($Log)
	Exit

Else
	;write the failure of truecrypt mounting to the console/logfile
	ConsoleWrite(@CRLF &amp; "Failed to mount:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
	FileWriteLine($Log, @CRLF &amp; "Failed to mount:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
	FileClose($Log)
EndIf

;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

Link to comment
Share on other sites

It's still not mounting the drive. I get this:

User Credentials:  ACCEPTED
User Credentials:  Username and/or Password recognised on:  UPSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\Backups to Drive:  z
Failed to map network drive:  \\UPSTAIRS\\unknownsoldierx$  the error returned is:  Undefined / Other error&gt;Exit code: 0    Time: 4.568

Link to comment
Share on other sites

It's still not mounting the drive. I get this:

User Credentials:  ACCEPTED
User Credentials:  Username and/or Password recognised on:  UPSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\Backups to Drive:  z
Failed to map network drive:  \\UPSTAIRS\\unknownsoldierx$  the error returned is:  Undefined / Other error&gt;Exit code: 0    Time: 4.568

Shessh, even after the new function to give more than exit code 0, all we still get is "Undefined / Other"

Yeah like thats helpful hey :)

Can you try in a command line:

net use x: \\upstairs\unknownsoldierx$ password /user:upstairs\username

where password is your password and username is your username

and tell me if that works....

Meanwhile i just saw another erroneous slash or two, not going to repost the entire script yet again....

The drive mapping section

        ; Map drives
        $Map1_Add = DriveMapAdd("x:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath1, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
        If $Map1_Add = 1 Then
                ;write the success of drive mapping to the console
                ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
                ;write the success of drive mapping to the logfile
                FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
                SetError(0)
        Else
                ;send @error to function  _MapError to give non-numerical explanation :)
                _MapError(@error)
                ;write the failure of drive mapping to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileClose($Log)
                Exit
        EndIf

        $Map2_Add = DriveMapAdd("y:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath2, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
        If $Map2_Add = 1 Then
                ;write the success of drive mapping to the console
                ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
                ;write the success of drive mapping to the logfile
                FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
                SetError(0)
        Else
                ;send @error to function  _MapError to give non-numerical explanation :)
                _MapError(@error)
                ;write the failure of drive mapping to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath2  &amp; "  the error returned is:  " &amp; @error)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath2  &amp; " the error returned is:  " &amp; @error)
                FileClose($Log)
                Exit
        EndIf

Should be:

        ; Map drives
        $Map1_Add = DriveMapAdd("x:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath1, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
        If $Map1_Add = 1 Then
                ;write the success of drive mapping to the console
                ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
                ;write the success of drive mapping to the logfile
                FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath1)
                SetError(0)
        Else
                ;send @error to function  _MapError to give non-numerical explanation :)
                _MapError(@error)
                ;write the failure of drive mapping to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileClose($Log)
                Exit
        EndIf

        $Map2_Add = DriveMapAdd("y:", "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath2, 0, $NetworkDomain &amp; "\" &amp; $NetworkUsername, $NetworkPassword)
        If $Map2_Add = 1 Then
                ;write the success of drive mapping to the console
                ConsoleWrite(@CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
                ;write the success of drive mapping to the logfile
                FileWriteLine($Log, @CRLF &amp; "Successfully mapped network drive:  " &amp; $MapDrivePath2)
                SetError(0)
        Else
                ;send @error to function  _MapError to give non-numerical explanation :)
                _MapError(@error)
                ;write the failure of drive mapping to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp;  $MapDrivePath2  &amp; "  the error returned is:  " &amp; @error)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; $MapDrivePath2  &amp; " the error returned is:  " &amp; @error)
                FileClose($Log)
                Exit
        EndIf

The offending lines are:

                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)

                ConsoleWrite(@CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)
                FileWriteLine($Log, @CRLF &amp; "Failed to map network drive:  " &amp; "\\" &amp; $MapDriveMachineName &amp; "\" &amp; $MapDrivePath1 &amp; "  the error returned is:  " &amp; $MapError)

The problem is the "\" & between $MapDriveMachineName & "\" & $MapDrivePath1 arrghh

Link to comment
Share on other sites

net use x: \\downstairs\unknownsoldierx$ password /user:upstairs\username

That won't work unless my truecrypt volume is mounted and the folder is shared.

I think you may be confused about \\DOWNSTAIRS\Locked$\Backups. "Backups" is the truecrypt volume. It's a file with no extension. "unknownsoldierx" is a folder inside that volume.

Link to comment
Share on other sites

net use x: \\downstairs\unknownsoldierx$ password /user:upstairs\username

That won't work unless my truecrypt volume is mounted and the folder is shared.

I think you may be confused about \\DOWNSTAIRS\Locked$\Backups. "Backups" is the truecrypt volume. It's a file with no extension. "unknownsoldierx" is a folder inside that volume.

User Credentials: ACCEPTED

User Credentials: Username and/or Password recognised on: UPSTAIRS

Successfully mounted: \\DOWNSTAIRS\Locked$\Backups to Drive: z

Failed to map network drive: \\UPSTAIRS\\unknownsoldierx$ the error returned is: Undefined / Other error>Exit code: 0 Time: 4.568

Follow this step by step as the script does it (the details gathered from the output) - the script is currently doing this (it can only work with what you put into it)

1) Check Credentials....OK

2) Mount truecrypt volume on DOWNSTAIRS pc using common username and password to Drive z...OK

3) Try and map network folder unknownsoldierx$ on UPSTAIRS pc...FAILS....Undefined / Other error>Exit code: 0

The command in the script that gives that last error is essentially same as:

net use x: \\upstairs\unknownsoldierx$ password /user:upstairs\username

If you cannot do this at the command prompt either then theres a problem.

Going back to your original bat with the sharing stuff in it:

@echo off

rem Mount True Crypt Volume
D:\TrueCrypt\TrueCrypt.exe /v D:\Locked\backups /l G /p password /q

rem Share folders
Net share share1$=G:\share1 /grant:username,FULL
Net share share2$=G:\share2 /grant:username,FULL

So you want to mount the truecrypt volume and then share 2 folders inside of it?

So i can understand better and try and finish it and get on with my life, are the folders always going to be the same, and always 2?

Link to comment
Share on other sites

1. credentials are OK.

2. "c:\program files\trueCrypt\truecrypt.exe" /v \\downstairs\locked$\backups /l z /p password

I was confused as to what the script was doing. Step 3 is unnecessary. Folder "unknownsoldierx" does not need to be shared, as it is available as z:\unknownsoldierx.

With my batch files, I was using psexec to run truecrypt on the remote machine, then sharing the folders so that I could access them remotely. Doing it this way is much easier. The only downside is that if I have connection issues, I may get an error that z: is not available and it may stop the job. That's not really a problem with the other method.

Link to comment
Share on other sites

For some reason i thought you wanted to map drives, not create a share on the truecrypt volume

Maybe i was having a really bad night the last 2 nights...totally possible i got muddled :)

1. credentials are OK.

2. "c:\program files\trueCrypt\truecrypt.exe" /v \\downstairs\locked$\backups /l z /p password

I was confused as to what the script was doing. Step 3 is unnecessary. Folder "unknownsoldierx" does not need to be shared, as it is available as z:\unknownsoldierx.

With my batch files, I was using psexec to run truecrypt on the remote machine, then sharing the folders so that I could access them remotely. Doing it this way is much easier. The only downside is that if I have connection issues, I may get an error that z: is not available and it may stop the job. That's not really a problem with the other method.

So you dont need ot map to any other netowrk location?

As long as the your truecrypt drive is mounted thats all you needed?

I think i added the mapping stuff just to give you an idea of how to do this in autoit and got out of hand, who knows its 4am again here, im gonna split soon

So try cutting & pasting the main script section over your last test and see if it does exactly what you need then

; script start


;test username and password, no point going through it all if it wont work
If RunAs($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, @ComSpec &amp; " /c VER", @WorkingDir, @SW_HIDE) Then
    ;write the success of user/pass to the console/logfile
        ConsoleWrite(@CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
        FileWriteLine($Log, @CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
Else
        ;write the failure of user/pass to the console/logfile
        ConsoleWrite(@CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
        FileWriteLine($Log, @CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
        FileClose($Log)
Exit
EndIf


;Mount True Crypt Volume
FileWriteLine($Log, @CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; $TC_Path &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
$TCMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe &amp; " /q /v " &amp; $TC_Path &amp; " /l" &amp; $TC_DriveLetter &amp; " /p " &amp; $TC_Password)

If NOT @error Or $TCMount = 0 Then

        ;write the success of truecrypt mounting to the console
        ConsoleWrite(@CRLF &amp; "Successfully mounted:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter)
        ;write it to the logfile
        FileWriteLine($Log, @CRLF &amp; "Successfully mounted:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter)

        ;Robocopy stuff
        $CopyLines = IniReadSection($RC_Ini, "Copy")
        If @error Then
                ;MsgBox(4096, "", "Error occurred, probably no INI file.")

                ;if there's a problem with the ini file (like being missing) write it to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to open Ini file:  " &amp; $RC_Ini &amp; " Error occurred, probably no INI file.")
                FileWriteLine($Log, @CRLF &amp; "Failed to open Ini file:  " &amp; $RC_Ini &amp; " Error occurred, probably no INI file.")
                Exit
        Else
                $NumberOfJobs = $CopyLines[0][0]
                For $i = 1 To $CopyLines[0][0]

                ;split value (containing ROBOCOPYOPTIONS,SOURCE,DESTINATION) into 3 separate variables at the comma
                $CopyLinesSplit = StringSplit($CopyLines[$i][1], ",")
                If $CopyLinesSplit[0] &lt; 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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - FAILED.")
                                FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - FAILED.")
                                $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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                "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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                "Skipping to next job...")
                                $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 &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; $CopySource &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; $CopyDestination)
                FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; $CopySource &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; $CopyDestination)
                $RoboCopy = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $RC_Path &amp; " " &amp; $RC_Options &amp; " " &amp; "/LOG+:" &amp; $RC_Log &amp; "Job_" &amp; $i &amp; "_robocopy.log" &amp; " " &amp; $CopySource &amp; " " &amp; $CopyDestination)
                ;Write copy result to console
                Switch @error
                        Case 0
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 0 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 0 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****")
                        Case 1
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  One or more files were copied successfully (that is, new files have arrived." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 1 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  One or more files were copied successfully (that is, new files have arrived." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 1 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** SUCCESS (COPY SUCCESSFUL) - CHECK ROBOCOPY LOG ****")
                        Case 2
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 2 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 2 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (EXTRA FILES) - CHECK ROBOCOPY LOG ****")
                        Case 4
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 4 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 4 means at least a partial robocopy success" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL SUCCESS (*MISMATCHES*) - CHECK ROBOCOPY LOG ****")
                        ;According to MS any error code greater than 8 means a possible robocopy failure
                         Case 8
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 8 means at least a partial robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 8 means at least a partial robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** PARTIAL FAILURE (**FAILED COPIES**) - CHECK ROBOCOPY LOG ****")
                                $NumberOfJobs -= 1
                        ;According to MS error code 16 means a robocopy failure
                         Case 16
                                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  to insufficient access privileges on the source or destination directories." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 16 means a robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
                                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  Serious error. Robocopy did not copy any files. This is either a usage error or an error due" &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  to insufficient access privileges on the source or destination directories." &amp; @CRLF &amp; _
                                "Job number:  " &amp; $i &amp; "  According to MS error code 16 means a robocopy failure" &amp; @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** COMPLETE FAILURE (***FATAL ERROR***) - CHECK ROBOCOPY LOG ****")
                                $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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****")
                                        FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****")
                                        $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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
                                        "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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                                        "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
                                        "Skipping to next job...")
                                        $NumberOfJobs -= 1
                        EndSelect

                EndIf
        EndIf
        Next
        EndIf


;write the number of successful jobs to console/logfile
ConsoleWrite(@CRLF &amp; $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")
FileWriteLine($Log, @CRLF &amp; $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")



        ;whack in a quick 2 second sleep
        Sleep(2000)

        ;Un-Mount True Crypt Volume
        $TCUnMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe &amp; " /q /d " &amp; $TC_DriveLetter)
        If @error Or $TCUnMount &gt; 0 Then
                ;write the failure of truecrypt unmounting to the console/logfile
                ConsoleWrite(@CRLF &amp; "Failed to unmount:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
                FileWriteLine($Log, @CRLF &amp; "Failed to unmount:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
        EndIf
        ;write the success of truecrypt unmounting to the console/logfile
        ConsoleWrite(@CRLF &amp; "Successfully unmounted:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter)
        FileWriteLine($Log, @CRLF &amp; "Successfully unmounted:  " &amp; $TC_Path &amp; " from Drive:  " &amp; $TC_DriveLetter)
        FileClose($Log)
        Exit

Else
        ;write the failure of truecrypt mounting to the console/logfile
        ConsoleWrite(@CRLF &amp; "Failed to mount:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
        FileWriteLine($Log, @CRLF &amp; "Failed to mount:  " &amp; $TC_Path &amp; " to Drive:  " &amp; $TC_DriveLetter &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
        FileClose($Log)
EndIf

;close the log file
FileClose($Log)

Link to comment
Share on other sites

User Credentials: ACCEPTED

User Credentials: Username and/or Password recognised on: UPSTAIRS

Successfully mounted: \\DOWNSTAIRS\Locked$\x_backups to Drive: z

Failed to open Ini file: D:\Programs\backups\robocopy.ini Error occurred, probably no INI file.>Exit code: 0 Time: 0.341

Still isn't mounting to z:, and the path to robocopy.ini is correct.

For the moment, this is all I have in the INI:

[Copy]
1,D:\Patrick,\\DOWNSTAIRS\Patrick$

Link to comment
Share on other sites

User Credentials: ACCEPTED

User Credentials: Username and/or Password recognised on: UPSTAIRS

Successfully mounted: \\DOWNSTAIRS\Locked$\x_backups to Drive: z

Failed to open Ini file: D:\Programs\backups\robocopy.ini Error occurred, probably no INI file.>Exit code: 0 Time: 0.341

Still isn't mounting to z:, and the path to robocopy.ini is correct.

For the moment, this is all I have in the INI:

[Copy]
1,D:\Patrick,\\DOWNSTAIRS\Patrick$

Are you saying if you open a command prompt and type z: theres no drive?

Well you need ot change the variable $RC_Ini

$RC_Ini = "path to robocopy.ini"

And try for your robocopy.ini file:

(you were leaving out the job number (i,e, 1), the =, then robocopy options)

[Copy]
1=*robocopy options*,D:\Patrick,\\DOWNSTAIRS\Patrick$

I gotta crash for a few hours

Link to comment
Share on other sites

Sleep well.

The path to robocopy was correct, I just forgot to change it to the new format. For now, I just have a simple shared folder job.

[Copy]
1=/mir /zb /dcopy:T /copyall /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

Here's what I get when I run the script:

User Credentials:  ACCEPTED
User Credentials:  Username and/or Password recognised on:  UPSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\backups to Drive:  z
Job number:  1  starting...
Job number:  1  RoboCopy Options:  /mir /zb /dcopy:T /copyall /xa:h
Job number:  1  Source Folder:  D:\Patrick
Job number:  1  Destination Folder:  \\DOWNSTAIRS\Patrick$
Job number:  1  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  1  According to MS error code 0 means at least a partial robocopy success
Job number:  1  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****
1  of  1  jobs completed successfully
Failed to unmount:  \\DOWNSTAIRS\Locked$\backups from Drive:  z
ExitCode:  1TrueCrypt returned error:  0
Successfully unmounted:  \\DOWNSTAIRS\Locked$\backups from Drive:  z&gt;Exit code: 0    Time: 2.721

Link to comment
Share on other sites

Sleep well.

The path to robocopy was correct, I just forgot to change it to the new format. For now, I just have a simple shared folder job.

[Copy]
1=/mir /zb /dcopy:T /copyall /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

Here's what I get when I run the script:

User Credentials:  ACCEPTED
User Credentials:  Username and/or Password recognised on:  UPSTAIRS
Successfully mounted:  \\DOWNSTAIRS\Locked$\backups to Drive:  z
Job number:  1  starting...
Job number:  1  RoboCopy Options:  /mir /zb /dcopy:T /copyall /xa:h
Job number:  1  Source Folder:  D:\Patrick
Job number:  1  Destination Folder:  \\DOWNSTAIRS\Patrick$
Job number:  1  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  1  According to MS error code 0 means at least a partial robocopy success
Job number:  1  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****
1  of  1  jobs completed successfully
Failed to unmount:  \\DOWNSTAIRS\Locked$\backups from Drive:  z
ExitCode:  1TrueCrypt returned error:  0
Successfully unmounted:  \\DOWNSTAIRS\Locked$\backups from Drive:  z&gt;Exit code: 0    Time: 2.721

Okay, so i have 2 questions:

Did you check the job_1_robocopy.log and check the files copied ok

and

Did you have anything else accessing the truecrypt volume while the script was running, like an explorer window, becausse any open file handle will stop it from unmounting

Link to comment
Share on other sites

Oh. I forgot to say, the script still doesn't mount the truecrypt volume. It is never mapped to Z:. I checked using explorer and the command prompt.

Here is the log:

Successfully mounted:  \\DOWNSTAIRS\Locked$\x_backups to Drive:  z

Job number:  1  starting...
Job number:  1  RoboCopy Options:  /mir /zb /dcopy:T /copyall /xa:h
Job number:  1  Source Folder:  D:\Patrick
Job number:  1  Destination Folder:  \\DOWNSTAIRS\Patrick$
Job number:  1  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  1  According to MS error code 0 means at least a partial robocopy success
Job number:  1  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****

1  of  1  jobs completed successfully

Failed to unmount:  \\DOWNSTAIRS\Locked$\x_backups from Drive:  z
ExitCode:  0TrueCrypt returned error:  0

Successfully unmounted:  \\DOWNSTAIRS\Locked$\x_backups from Drive:  z

I am able to mount the truecrypt volume via the cmd prompt like this:

"c:\program files\trueCrypt\truecrypt.exe" /v \\downstairs\locked$\backups /l z /p password

Link to comment
Share on other sites

Oh. I forgot to say, the script still doesn't mount the truecrypt volume. It is never mapped to Z:. I checked using explorer and the command prompt.

Here is the log:

Successfully mounted:  \\DOWNSTAIRS\Locked$\x_backups to Drive:  z

Job number:  1  starting...
Job number:  1  RoboCopy Options:  /mir /zb /dcopy:T /copyall /xa:h
Job number:  1  Source Folder:  D:\Patrick
Job number:  1  Destination Folder:  \\DOWNSTAIRS\Patrick$
Job number:  1  No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
Job number:  1  According to MS error code 0 means at least a partial robocopy success
Job number:  1  **** SUCCESS (NO CHANGE) - CHECK ROBOCOPY LOG ****

1  of  1  jobs completed successfully

Failed to unmount:  \\DOWNSTAIRS\Locked$\x_backups from Drive:  z
ExitCode:  0TrueCrypt returned error:  0

Successfully unmounted:  \\DOWNSTAIRS\Locked$\x_backups from Drive:  z

I am able to mount the truecrypt volume via the cmd prompt like this:

"c:\program files\trueCrypt\truecrypt.exe" /v \\downstairs\locked$\backups /l z /p password

Try changing the current

$TCMount = RunAs($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, $TC_Exe &amp; " /q /v " &amp; $TC_Path &amp; " /l" &amp; $TC_DriveLetter &amp; " /p " &amp; $TC_Password)

with

$TCMount = RunAs($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) &amp; $TC_Exe &amp; Chr(34) &amp; " /q /v " &amp; $TC_Path &amp; " /l" &amp; $TC_DriveLetter &amp; " /p " &amp; $TC_Password)

the change is the addition of the chr(34) before and after TC_Path, this wraps the path in quotations got when you have folders with spaces obviously

Chr(34) &amp; $TC_Exe &amp; Chr(34)

Other than the above being a possibility, the only way i can get the tc volume to NOT mount is put in a incorrect username or password, if i do that i can then and only then get an error like youre reporting

Please double check the $NetworkUsername and $NetworkPassword variables are correct

Link to comment
Share on other sites

I thought that change would do it, but I'm still getting the same error. My network username and password variables are correct.

Link to comment
Share on other sites

Sorry, been away for a couple of days, and going away again in 2 days.

Im scratching my head to think of a way that its still possible for that to fail

Ill think more on it later tonight

Link to comment
Share on other sites

Should have an updated script for you tomorrow, sorry, but snowed under here

Made quite a few additions , more error checking

If you still fail to mount your drive after this, its not my fault :)

Link to comment
Share on other sites

Okay,

Changes/Additions:

* Enclosed all paths that might *possibly* include spaces in quotation marks...done and tested

* Outputting of truecrypt container mounting command line to console/log for troubleshooting...done and tested

* Check source folder accessible...done and tested

* Check destination drive (you may be creating the destination folder as part of copy, so no good checking for destination folder) accessible...done and tested

* Changed Robocopy exit codes to be short and more inline with MS shortened error descriptions

* Tidied up console/logfile output

* Tidied up script generally

#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 &lt;Array.au3&gt;

; 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", 1)


;====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 &amp; " /c VER", @WorkingDir, @SW_HIDE) Then
    ;write the success of user/pass to the console/logfile
        ConsoleWrite(@CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
        FileWriteLine($Log, @CRLF &amp; "User Credentials:  ACCEPTED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password recognised on:  " &amp; $NetworkDomain)
Else
    ;write the failure of user/pass to the console/logfile
        ConsoleWrite(@CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
        FileWriteLine($Log, @CRLF &amp; "User Credentials:  FAILED" &amp; @CRLF &amp; "User Credentials:  Username and/or Password not recognised on:  " &amp; $NetworkDomain)
        FileClose($Log)
Exit
EndIf

;Mount True Crypt Volume
ConsoleWrite(@CRLF &amp; @CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
FileWriteLine($Log, @CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
ConsoleWrite(@CRLF &amp; "Using command line:  " &amp; Chr(34) &amp; $TC_Exe &amp; Chr(34) &amp; " /q /v " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; " /l" &amp; $TC_DriveLetter &amp; " /p password")
FileWriteLine($Log, "Using command line:  " &amp; Chr(34) &amp; $TC_Exe &amp; Chr(34) &amp; " /q /v " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; " /l" &amp; $TC_DriveLetter &amp; " /p password")

$TCMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) &amp; $TC_Exe &amp; Chr(34) &amp; " /q /v " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; " /l" &amp; $TC_DriveLetter &amp; " /p " &amp; $TC_Password)
If NOT @error Or $TCMount = 0 Then

        ;write the success of truecrypt mounting to the console
        ConsoleWrite(@CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....MOUNTED")
        ;write it to the logfile
        FileWriteLine($Log, "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....MOUNTED")
Else
        ;write the failure of truecrypt mounting to the console/logfile
        ConsoleWrite(@CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....FAILED" &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
        FileWriteLine($Log, @CRLF &amp; "Attempting to mount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....FAILED" &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCMount)
        FileClose($Log)
EndIf

;Robocopy stuff
ConsoleWrite(@CRLF &amp; @CRLF &amp; "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....")
FileWriteLine($Log, @CRLF &amp; "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....")
$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 &amp; "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....FAILED" &amp;  _
	"Attempting to open job list file:  " &amp; $RC_Ini &amp; " .... Error occurred, probably no INI file.")
    FileWriteLine($Log, "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....FAILED" &amp;  _
	"Attempting to open job list file:  " &amp; $RC_Ini &amp; " .... Error occurred, probably no INI file.")
    Exit
Else
	ConsoleWrite(@CRLF &amp; "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....SUCCESSFUL")
	FileWriteLine($Log, "Attempting to open job list file:  " &amp; $RC_Ini &amp; " ....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 &amp; @CRLF &amp; "Processing jobs....")
	FileWriteLine($Log, @CRLF &amp; "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] &lt; 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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - FAILED.")
                FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - 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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "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 &amp; "Job number:  " &amp; $i &amp;  "  - Missing value in Ini File" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp;  "  - ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "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 &amp; @CRLF &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; Chr(34) &amp; $CopyDestination &amp; Chr(34))
        FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp;  "  starting..." &amp;  @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  RoboCopy Options:  " &amp; $RC_Options &amp; @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  Source Folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; @CRLF &amp; _
        "Job number:  " &amp; $i &amp;  "  Destination Folder:  " &amp; Chr(34) &amp; $CopyDestination &amp; Chr(34))

	    ;check source folder exists
		ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " exists....")
		FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " exists....")
		$CheckSourceFolder = FileExists($CopySource)
		If $CheckSourceFolder = 0 Then
			ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " exists....FAILED")
			FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " exists....FAILED")
			;skip to next job
			ContinueLoop
		Else
			ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " exists....SUCCESS")
			FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking source folder:  " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " 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 &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....")
		FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....")
		If $CheckDestinationFolder &lt;&gt; $TC_DriveLetter Then
			$CheckDestinationFolder2 = DriveStatus(StringLeft($CopyDestination, 3))
			Select
				Case "UNKNOWN"
					ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....FAILED: UNKNOWN" &amp; _
					@CRLF &amp; "ERROR returned message - UKNOWN - Drive may be unformatted (RAW).")
					FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....FAILED: UNKNOWN" &amp; _
					@CRLF &amp; "Drive may be unformatted (RAW).")
					;decrease the amount of successful jobs by 1
					$NumberOfJobs -= 1
					;skip to next job
					ContinueLoop
				Case "READY"
					ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....SUCCESS: DRIVE READY")
					FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....SUCCESS: DRIVE READY")
				Case "INVALID"
					ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp;" exists and is accessible....FAILED: INVALID" &amp; _
					@CRLF &amp; "ERROR returned message - INVALID - May indicate the drive letter does not exist or that a mapped network drive is inaccessible.")
					FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....FAILED: INVALID" &amp; _
					@CRLF &amp; "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 &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....FAILED: UKNOWN" &amp; _
					@CRLF &amp; "ERROR returned message - INVALID - Drive may be unformatted (RAW).")
					FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....FAILED: UKNOWN" &amp; _
					@CRLF &amp; "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 &amp; "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....SUCCESS: DRIVE READY (Using TrueCrypt Container)")
			FileWriteLine($Log, "Job number:  " &amp; $i &amp;  "  Checking destination drive:  " &amp; $CheckDestinationFolder &amp; " exists and is accessible....SUCCESS: DRIVE READY (Using TrueCrypt Container)")
		EndIf

		;do the actual copying
        $RoboCopy = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) &amp; $RC_Path &amp; Chr(34) &amp; " " &amp; $RC_Options &amp; " " &amp; "/LOG+:" &amp; Chr(34) &amp; $RC_Log &amp; "Job_" &amp; $i &amp; "_robocopy.log" &amp; Chr(34) &amp; " " &amp; Chr(34) &amp; $CopySource &amp; Chr(34) &amp; " " &amp; Chr(34) &amp; $CopyDestination&amp; Chr(34))
        ;Write copy result to console
        Switch @error
            Case 0
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  NO CHANGE **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  NO CHANGE **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 1
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  COPY **** SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  COPY **** SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 2
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 3
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 4
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM **** SUCPARTIAL CESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 5
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 6
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM XTRA **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 7
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  MISM XTRA COPY **** PARTIAL SUCCESS **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
            Case 8
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
				;decrease the amount of successful jobs by 1
				$NumberOfJobs -= 1
            Case 9
                ConsoleWrite(@CRLF &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL MISM  **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL MISM COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  AIL MISM XTRA **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  FAIL MISM XTRA COPY **** FAIL **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  ROBOCOPY reports:  **** FATAL ERROR **** - CHECK ROBOCOPY LOG OR FURTHER INFO")
                FileWriteLine($Log, "Job number:  " &amp; $i &amp; "  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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****")
                FileWriteLine($Log, @CRLF &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  **** 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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
                "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 &amp; "Job number:  " &amp; $i &amp; "  **** Blank value in Ini File *****" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  ERROR: expecting Robocopy Options, Source, Destination. One is missing" &amp; @CRLF &amp; _
                "Job number:  " &amp; $i &amp; "  **** FAILURE - CHECK INI FILE ****" &amp; @CRLF &amp; _
                "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 &amp; @CRLF &amp; $TotalNumberOfJobs &amp; "  total jobs submitted for  processing")
FileWriteLine($Log, @CRLF &amp; $TotalNumberOfJobs &amp; "  total jobs submitted for  processing")

;write the number of successful jobs to console/logfile
ConsoleWrite(@CRLF &amp; $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")
FileWriteLine($Log, $NumberOfJobs &amp; "  of  " &amp; $CopyLines[0][0] &amp; "  jobs completed successfully")

;whack in a quick 2 second sleep
Sleep(2000)

;Un-Mount True Crypt Volume
ConsoleWrite(@CRLF &amp; @CRLF &amp; "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
FileWriteLine($Log, @CRLF &amp; "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....")
$TCUnMount = RunAsWait($NetworkUsername, $NetworkDomain, $NetworkPassword, 0, Chr(34) &amp; $TC_Exe &amp; Chr(34) &amp; " /q /d " &amp; $TC_DriveLetter)
If @error Or $TCUnMount &gt; 0 Then
    ;write the failure of truecrypt unmounting to the console/logfile
    ConsoleWrite(@CRLF &amp; "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....FAILED" &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
    FileWriteLine($Log, "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....FAILED" &amp; @CRLF  &amp; "ExitCode:  " &amp; @error &amp; "TrueCrypt returned error:  " &amp; $TCUnMount)
EndIf

;write the success of truecrypt unmounting to the console/logfile
ConsoleWrite(@CRLF &amp; "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....UNMOUNTED")
FileWriteLine($Log, "Attempting to unmount truecrypt volume:  " &amp; Chr(34) &amp; $TC_Path &amp; Chr(34) &amp; "  on drive letter:  " &amp; $TC_DriveLetter &amp; " ....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

Link to comment
Share on other sites

Drive still doesn't mount. And now my test backup job doesn't work.

I ran 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

robocopy.ini

[Copy]
1=/mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

Copylog:

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

I've posted over at the AutoIt forums to see if anyone has any ideas.

http://www.autoitscript.com/forum/index.php?showtopic=117772

Link to comment
Share on other sites

Drive still doesn't mount. And now my test backup job doesn't work.

I ran 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

robocopy.ini

[Copy]
1=/mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

robocopy.ini

[Copy]
1=/mir /dcopy:T /copy:DATO /xd "D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

One thing for starters, youre missing a comma after the robocopy options:

1=/mir /dcopy:T /copy:DATO /xd,"D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

Then theres the options that appear in the wrong place /xa:h

1=/mir /dcopy:T /copy:DATO /xd,"D:\Patrick\Downloads" "D:\Patrick\Desktop" /xa:h,D:\Patrick,\\DOWNSTAIRS\Patrick$

It should be:

1=/mir /dcopy:T /copy:DATO /xd /xa:h,"D:\Patrick\Downloads" "D:\Patrick\Desktop" ,D:\Patrick,\\DOWNSTAIRS\Patrick$

The next issue is why there are 3 sets of folders listed:

"D:\Patrick\Downloads" "D:\Patrick\Desktop" ,D:\Patrick,\\DOWNSTAIRS\Patrick$

As noted before, and in the top of the script, the ini file format i used was:

job number = robocopy optionscommasource foldercommadestination folder

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.