zvikush Posted April 1, 2007 Posted April 1, 2007 hey everybody! I'm currently into a project of automatic backup's and i need a bit of help... how can I safely remove a drive within my script?!?! and also how can i get it back?!?!? p.s. my way of thinking is to leave the mobile hard drive always attatchd to the USB port, to turn it on only when my script starts and to safely remove it when it's over... hard isn't it? please help...
zvikush Posted April 1, 2007 Author Posted April 1, 2007 still no reply? is my problem not understood or does no one have a solution for me? come on people give a young autoiter a break...
Eru Posted April 1, 2007 Posted April 1, 2007 From what I'm understanding, you want a script to copy a USB drive when it's put in, and then dismount the drive when It's finished? What code do you have so far?
zvikush Posted April 1, 2007 Author Posted April 1, 2007 exactly the opposite... i want a script which will back up files from the hard drive to a disc-on-key. the script is already done but the problem is that the device is always mounted which make it volreneble to viruses etc. i want to mount it whan my script starts and demount it when it ends. the script is done, besides the mount-demount operation! anything on your mind?
zvikush Posted April 2, 2007 Author Posted April 2, 2007 o.k. i realize that in auto it there is no solution to my problem... maybee something in the registry,cmd or bat? if anybody knows something like that i will be glad to listen... by the way i will addon my script... i think this is nice for a third script ever... the cool thing is that the script will only work on a computer which the mac address is the same as the one in the script... #include <GUIConstants.au3> #include <file.au3> #include <array.au3> ;#NoTrayIcon $mac="00-0D-60-7B-40-45" Dim $aRecords $drives_list = DriveGetDrive( "all" ) $num_of_rem = 1 ;removable drives counter for array increment $source_path = "c:\magic" dim $rem_array[10] ;an array which includes the removeble drives in it TrayTip("מערכת הגיבויים", "כרגע מתבצע גיבוי", 30, 1) FileDelete (@ScriptDir & "\logs\last_opp.txt") RunWait ( @ComSpec & " /c ipconfig /all > c:\1.txt" ) If Not _FileReadToArray("c:\1.txt",$aRecords) Then Exit EndIf ;_ArrayDisplay( $aRecords, "Class List of Active Window" ) For $n = 0 to $aRecords[0] if (stringInStr ($aRecords[$n], $mac)) then ;start the GUI for the backup program For $i = 1 to $drives_list[0] $var = DriveGetType( $drives_list[$i] ) if $var = "removable" Then $rem_array[$num_of_rem] = $drives_list[$i] $num_of_rem = $num_of_rem+1 EndIf Next ;segment that trims the unusefull parts of the array ;_ArrayDisplay( $rem_array, "this is the removable disks array before trimming" ) $rem_array[0]=UBound ( $rem_array ) $i=$rem_array[0]-1 while $i<>0 if $rem_array[$i] = "0" Then _ArrayDelete( $rem_array,$i) $i = $i-1 ElseIf $rem_array[$i] = "a:" Then _ArrayDelete( $rem_array,$i) $i = $i-1 Elseif $rem_array[$i] = "b:" Then _ArrayDelete( $rem_array,$i) $i = $i-1 else $i = $i-1 EndIf WEnd $rem_array[0]=UBound ( $rem_array ) ;_ArrayDisplay( $rem_array, "Class List of Active Window" ) ;segment that identifies who is the source disk and who is the destination and preforms the backup for $i=1 To $rem_array[0]-1 if FileExists ( $rem_array[$i]&"\destination" ) Then if FileExists ( "c:\magic" ) Then if FileExists ( "c:\mg5.6" ) Then if FileExists ( "c:\mg7.0" ) Then if FileExists ( $rem_array[$i]& "\גיבוי_אוטומטי" ) Then if not FileExists ( $rem_array[$i]& "\היסטוריה" ) Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","creating main history folder") $a=DirCreate ($rem_array[$i]& "\היסטוריה") if $a= "0" Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr creating main history folder") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr creating main history folder") Exit EndIf EndIf if FileExists ( $rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן_1" ) Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","removing auto backup old 1 from history "&$rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן_1") $b=DirRemove ($rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן_1",1 ) if $b= "0" Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr removing auto backup old 1 from history") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr removing auto backup old 1 from history") Exit EndIf EndIf if FileExists ( $rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן" ) Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","renaming auto backup old to auto backup old 1 in history "&$rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן to " &$rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן_1") $c=DirMove ($rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן",$rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן_1",1) if $c= "0" Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr renaming auto backup old to auto backup old 1 in history") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr renaming auto backup old to auto backup old 1 in history") Exit EndIf EndIf _FileWriteLog(@ScriptDir & "\logs\last_opp.txt"," renaming & moving auto backup to auto backup old "&$rem_array[$i]& "\גיבוי_אוטומטי to "& $rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן") $d=dirmove ($rem_array[$i]& "\גיבוי_אוטומטי",$rem_array[$i]& "\היסטוריה" & "\גיבוי_אוטומטי_ישן") if $d= "0" Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr renaming & moving auto backup to auto backup old " ) _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr renaming & moving auto backup to auto backup old") Exit EndIf EndIf _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","creating auto backup dir "& $rem_array[$i]&"\גיבוי_אוטומטי" ) ;msgbox (4096,"","") $e=DirCreate ($rem_array[$i]&"\גיבוי_אוטומטי") if $e= "0" Then _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr creating auto backup dir" ) _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr creating auto backup dir") Exit EndIf ;msgbox (4096,"","") $1 = DirCopy ( "c:\magic",$rem_array[$i]&"\גיבוי_אוטומטי\magic") If $1 = "0" Then msgbox (4096,"", "קיימת שגיאה בהעתקת אחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr copying folder c:\magic") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr copying folder c:\magic") Exit EndIf $2 = DirCopy ( "c:\mg5.6",$rem_array[$i]&"\גיבוי_אוטומטי\mg5.6") If $2 = "0" Then msgbox (4096,"", "קיימת שגיאה בהעתקת אחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr copying folder c:\mg5.6") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr copying folder c:\mg5.6") Exit EndIf $3 = DirCopy ( "c:\mg7.0",$rem_array[$i]&"\גיבוי_אוטומטי\mg7.0") If $3 = "0" Then msgbox (4096,"", "קיימת שגיאה בהעתקת אחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","erorr copying folder c:\mg7.0") _FileWriteLog(@ScriptDir & "\logs\auto.txt","erorr copying folder c:\mg7.0") Exit EndIf FileDelete ("c:\1.txt") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","automatic backup completed successfully") _FileWriteLog(@ScriptDir & "\logs\auto.txt","automatic backup completed successfully") Exit Else msgbox (4096, "", "קיימת בעייה באחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","backup failed: folder c:\mg7.0 missing") _FileWriteLog(@ScriptDir & "\logs\auto.txt","backup failed: folder c:\mg7.0 missing") Exit EndIf Else msgbox (4096, "", "קיימת בעייה באחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","backup failed: folder c:\mg5.6 missing") _FileWriteLog(@ScriptDir & "\logs\auto.txt","backup failed: folder c:\mg5.6 missing") Exit EndIf Else msgbox (4096, "", "קיימת בעייה באחת מתיקיות המקור") _FileWriteLog(@ScriptDir & "\logs\last_opp.txt","backup failed: folder c:\magic missing") _FileWriteLog(@ScriptDir & "\logs\auto.txt","backup failed: folder c:\magic missing") Exit EndIf EndIf Next EndIf Next FileDelete ("c:\1.txt") MsgBox (4096," !!!", "no authorization to this computer!!!")
zvikush Posted April 7, 2007 Author Posted April 7, 2007 anybody?!?!?!?!? it's been a week allready i'm stuck?!?!? anyone knows of another forum that might have an answer to me in another language? (bat,registery,command-line, etc.)
lupusbalo Posted April 7, 2007 Posted April 7, 2007 to "unmount your drive" and be sure that there is no pending IO, u can use "sync" from sysinternals (it flushes all pending IOs) make a run from your script I dont know how to actualy "Unmount" the device, an idea could be some "clicks" on the system tray on the "remove device sucurely" system function I see no way for "mounting" lupus
kjason Posted July 5, 2007 Posted July 5, 2007 (edited) This is not a professional but very easy way to have the eject function in your script. I am using a external application "removedrive.exe" (http://www.uwe-sieber.de/files/removedrive.zip) which works like this way "removedrive -s e:" Then e: is removed from the system. "-s" option is for self deletion. You can use it in this way. =================================================================== #include #include <RemoveDrive.exe.au3> $driveletter=stringleft(@ScriptDir, 2) _eject() Func _eject() $File = FileOpen(@TempDir & "\removedrive.exe", 2 + 16) FileWrite($File, RemoveDriveEXE()) FileClose($File) ShellExecute("removedrive.exe",$driveletter & " -w:100 -i -s ", @TempDir,"",@SW_HIDE) EndFunc ==================================================================== If you want to include this file "removedrive.exe" make it into binary script "removedrive.exe.au3" and then include into your main script. ( removedrive.exe.au3 is attahced ) I hope it helps you a little.removedrive.rar Edited July 5, 2007 by kjason
XoloX Posted July 8, 2007 Posted July 8, 2007 There is another Way OuT!.....u can use vbscripts..........i have posted below a working example....... THE VBSCRIPT(Copy and paste in notepad and save as ejectdrive.vbs) ----------------------------START COPY------------------------------------------ Option Explicit On Error Resume Next CONST SSF_DRIVES = 17 Dim oShell, oNameSpace, oDrive, strDrive ' Set the Default Drive Letter strDrive = "i:\" strName="WritePROTecH" If Wscript.Arguments.Count > 0 Then strDrive = Wscript.Arguments.Unnamed.Item(0) End If Set oShell = CreateObject("Shell.Application") Set oNamespace = oShell.NameSpace(SSF_DRIVES) Set oDrive = oNamespace.ParseName(strDrive) oDrive.InvokeVerb "E&ject" ' Message can be displayed(optional) MsgBox strName & " drive ejected. You can now remove the device safely." -------------------------END COPY-------------------------------------------------------------- Then u have to make a script to install it in the c:\windows directory and run it using wscript.exe Eg: ;;USB EJECTION ;;Coded By XoloXx $windir=@WindowsDir FileInstall("ejectdrive.vbs",@WindowsDir & "\ejectdrive.vbs") Run("wscript.exe "& @WindowsDir & "\ejectdrive.vbs") Beep(1000,1000) Then simply run the au3!!
ChrisL Posted July 8, 2007 Posted July 8, 2007 (edited) Edit: Forum went screwey and double posted my reply! Edited July 8, 2007 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
ChrisL Posted July 8, 2007 Posted July 8, 2007 XoloX said: There is another Way OuT!.....u can use vbscripts..........i have posted below a working example....... THE VBSCRIPT(Copy and paste in notepad and save as ejectdrive.vbs) ----------------------------START COPY------------------------------------------ Option Explicit On Error Resume Next CONST SSF_DRIVES = 17 Dim oShell, oNameSpace, oDrive, strDrive ' Set the Default Drive Letter strDrive = "i:\" strName="WritePROTecH" If Wscript.Arguments.Count > 0 Then strDrive = Wscript.Arguments.Unnamed.Item(0) End If Set oShell = CreateObject("Shell.Application") Set oNamespace = oShell.NameSpace(SSF_DRIVES) Set oDrive = oNamespace.ParseName(strDrive) oDrive.InvokeVerb "E&ject" ' Message can be displayed(optional) MsgBox strName & " drive ejected. You can now remove the device safely." -------------------------END COPY-------------------------------------------------------------- Then u have to make a script to install it in the c:\windows directory and run it using wscript.exe Eg: ;;USB EJECTION ;;Coded By XoloXx $windir=@WindowsDir FileInstall("ejectdrive.vbs",@WindowsDir & "\ejectdrive.vbs") Run("wscript.exe "& @WindowsDir & "\ejectdrive.vbs") Beep(1000,1000) Then simply run the au3!! This is a crude translation of the above. There is no error checking you should write some! EjectDrive("F:\") Func EjectDrive($dLetter) Local CONST $SSF_DRIVES = 17 Local $oShell, $oNameSpace, $oDrive, $strDrive $strDrive = $dLetter $strName=DriveGetLabel ( $strDrive ) & "(" & $strDrive & ")" $oShell = ObjCreate("Shell.Application") $oNamespace = $oShell.NameSpace($SSF_DRIVES) $oDrive = $oNamespace.ParseName($strDrive) $oDrive.InvokeVerb ("E&ject") MsgBox(0,"", $strName & " drive ejected. You can now remove the device safely.") Endfunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
BAM5 Posted December 9, 2007 Posted December 9, 2007 Well since it has been about 8 months and zvikush has only 8 posts I doubt he will be on here any longer but to "detach" and "reattach" the device you would need to go to the device manager (My computer>right click>Properties>Hardware>Device Manager) click on the computer name and then find your device on the list, double click it and either enable or disable it. It acts the same as attaching and detaching it. I gave you the how now you just have to code it, HAVE FUN!!!! [center]JSON Encoding UDF[/center]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now