I have been asked to create a pretty simple idiot proof backup utility for users to take a snapshot of specific directories. I am using Truecrypt on USB drive for encryption. Right now I have the script hard coded to use T: for the encrypted container but would really like some way of letting Truecrypt use 'first available' in the very rare event T: is being used for something else. Here is what I have so far. Any tips on how to accomplish this would be greatly appreciated.
Thanks
;USB Backup
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
;Check if first time run and if so force password change
$FirstCheck = FileExists(@ScriptDir & "\firstrun")
If $FirstCheck = 1 Then Call("PasswordChange")
; Create Backup GUI
$Backup = GuiCreate("Backup Utility", 230, 120)
GuiSetIcon(@ScriptDir&"\Truecrypt\nw.ico")
; Create Backup GUI BUTTONS
$Button_Backup = GuiCtrlCreateButton("Backup", 10, 10, 100, 100)
$Button_Restore = GUICtrlCreateButton("Restore", 120, 10, 100, 100)
;$Button_Exit = GUICtrlCreateButton("Exit", 65, 120, 100, 100)
; Show GUI
GuiSetState(@SW_SHOW,$Backup)
;Unmap T Drive
DriveMapDel("T:")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button_Backup
GuiSetState(@SW_HIDE,$Backup)
Run(@ScriptDir&"\TrueCrypt\TrueCrypt.exe /q background /lt /m rm /v nwbackup.tc")
WinWaitActive("Enter password")
WinWaitClose("Enter password")
Do
$DrvStatus = DriveStatus("T:")
Sleep(1000)
Until $DrvStatus = "READY"
SplashTextOn("NW Backup", @CRLF&"Backing up My Documents", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@MyDocumentsDir&'" t:\backups\mydocs\ *.* /MIR')
SplashTextOn("NW Backup", @CRLF&"Backing up Desktop", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@DesktopDir&'" t:\backups\desktop\ *.* /MIR')
SplashTextOn("NW Backup", @CRLF&"Backing up Favorites", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@FavoritesDir&'" t:\backups\favorites\ *.* /MIR')
SplashTextOn("NW Backup", @CRLF&"Backing up Misc.", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@ProgramFilesDir&'\LOTUS\NOTES\DATA\" t:\backups\lnotes\ names.nsf /MIR')
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@ProgramFilesDir&'\NWDESKTOP\" t:\backups\NWDESKTOP\ *.* /MIR')
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe "'&@ProgramFilesDir&'\NWDESKTOP_BACKUP\" t:\backups\NWDESKTOP_BACKUP\ *.* /MIR')
SplashOff()
MsgBox(0,"NW Backup","Backup Complete")
Run(@ScriptDir&"\TrueCrypt\TrueCrypt.exe /q /dt")
SplashTextOn("NW Backup",@CRLF&"Please wait while the encrypted container is dismounted.",425,75)
Do
$DrvStatus = DriveStatus("T:")
Sleep(1000)
Until $DrvStatus = "Invalid"
SplashOff()
MsgBox(0,"NW Backup","It is now safe to remove your drive")
Exit
Case $msg = $Button_Restore
GuiSetState(@SW_HIDE,$Backup)
Run(@ScriptDir&"\TrueCrypt\TrueCrypt.exe /q background /lt /m rm /v nwbackup.tc")
WinWaitActive("Enter password")
WinWaitClose("Enter password")
Do
$DrvStatus = DriveStatus("T:")
Sleep(1000)
Until $DrvStatus = "READY"
SplashTextOn("NW Backup", @CRLF&"Restoring My Documents", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\mydocs\ "'&@MyDocumentsDir&'" *.* /E')
SplashTextOn("NW Backup", @CRLF&"Restoring Desktop", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\desktop\ "'&@DesktopDir&'" *.* /E')
SplashTextOn("NW Backup", @CRLF&"Restoring Favorites", 300, 75)
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\favorites\ "'&@FavoritesDir&'" *.* /E')
SplashTextOn("NW Backup", @CRLF&"Restoring Misc.")
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\lnotes\ "'&@ProgramFilesDir&'\LOTUS\NOTES\DATA\" names.nsf /E')
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\NWDESKTOP\ "'&@ProgramFilesDir&'\NWDESKTOP\" *.* /E')
RunWait(@COMSPEC & ' /c '&@ScriptDir&'robocopy.exe t:\backups\NWDESKTOP_BACKUP\ "'&@ProgramFilesDir&'\NWDESKTOP_BACKUP\" *.* /E')
SplashOff()
MsgBox(0,"NW Backup","Restore Complete")
Run(@ScriptDir&"\TrueCrypt\TrueCrypt.exe /q /dt")
SplashTextOn("NW Backup",@CRLF&"Please wait while the encrypted container is dismounted.",300,75)
Do
$DrvStatus = DriveStatus("T:")
Sleep(1000)
Until $DrvStatus = "Invalid"
SplashOff()
MsgBox(0,"NW Backup","It is now safe to remove your drive")
Exit
EndSelect
WEnd
Func PasswordChange()
$i = 1
MsgBox(0, "Password Change", "This appears to be your first time using this utility. You must now select a password")
$CHPW = GUICreate("Password Change",300,200)
GuiCtrlCreateLabel("Please select a new password and confirm"&@CRLF&@CRLF&"Password needs to be at least 8 characters in length", 10, 10, 280, 50)
$INPUT_1 = GUICtrlCreateInput("New Password",5,100,290,20,$ES_PASSWORD)
$INPUT_2 = GUICtrlCreateInput("Confirm Password",5,125,290,20,$ES_PASSWORD)
$Button_OK = GUICtrlCreateButton("OK", 130, 152, 40, 40)
GUISetState(@SW_SHOW,$CHPW)
While $i = 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button_OK
$NEWPW = GUICtrlRead($INPUT_1)
$CONFIRMPW = GUICtrlRead($INPUT_2)
If StringLen($NEWPW) <= 7 Then
MsgBox(0, "Pasword Length", "Password is to short. Password needs to be at least 8 characters in length.")
ElseIf StringCompare($NEWPW, $CONFIRMPW) <> 0 Then
MsgBox(0, "Password Mismatch", "Passwords do not match!")
Else
$i = 0
EndIf
EndSelect
Wend
MsgBox(0,"NOTICE!","Password change can take up to 2 minutes. Please do not touch the keyboard or mouse."&@CRLF&@CRLF&"Click OK to begin.")
GUISetState(@SW_HIDE,$CHPW)
SplashTextOn("NW Backup","Changing Password...Please Wait",300,75)
Run(@ScriptDir & "\Truecrypt\Truecrypt.exe")
WinWaitActive("TrueCrypt")
Send("!F")
WinWaitActive("Select a TrueCrypt Volume")
Send(@Scriptdir&"nwbackup.tc{ENTER}")
Send("{ALT}vcc{ENTER}")
WinWaitActive("Change Password or Keyfiles")
Send("nwdefault{TAB}{TAB}{TAB}"&$NEWPW&"{TAB}"&$CONFIRMPW&"{TAB}{ENTER}")
WinWaitActive("TrueCrypt","WARNING")
Send("!Y")
WinWaitActive("TrueCrypt","Password")
Send("{ENTER}")
WinWaitActive("TrueCrypt","&Create Volume")
Send("!X")
SplashOff()
MsgBox(0,"Password change","Password change complete."&@CRLF&@CRLF&"Click OK to return.")
FileDelete(@ScriptDir & "\firstrun")
EndFunc