Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Check all removables for a file then do action - Error :(

$
0
0

Hey,

 

I got a little problem while making a little tool. It works this way: You plug in a removable drive (USB) and as soon as it get's plugged in it checks

for a file called "password.dat", if it exists it reads the file and if my chosen password "U28e+dje33eefF" matches, i gives a massagebox/executes a function.

 

Now i wrote this: 

AutoIt         
  1. #include <File.au3>
  2.  
  3. drives ()
  4. check ()
  5. sleep(500)
  6.  
  7.  
  8.  
  9.  
  10. func check ()
  11. $file = "database.dat"
  12. FileOpen($file, 0)
  13. For $i = 1 to _FileCountLines($file)
  14.     $line = FileReadLine($file, $i)
  15. If $line = "U28e+dje33eefF" Then
  16. MsgBox (0,"","ITS IT")
  17. sleep(500)
  18. FileClose($file)
  19.  
  20. func drives ()
  21. $hFO = FileOpen("database.dat", 2)
  22. FileWrite($hFO, "")
  23. FileClose($hFO)
  24. Local $aArray = DriveGetDrive("REMOVABLE")
  25.    
  26.     For $i = 1 To $aArray[0]
  27.       FileWrite("database.dat", ($aArray[$i]) & "\password.dat"& @CRLF)      
  28.     Next

Now exactly what my program should currently do: Always check for all current removables and then check if the file exists, if not it does nothing, if it

exists it reads the file for the password. If the password matches, it should execute a message box saying "ITS IT".

 

I know there is an error: Where the password gets checked, it checks the database.dat file instead of the password.dat file. When changing it to this:

AutoIt         
  1. #include <File.au3>
  2.  
  3. drives ()
  4. check ()
  5. sleep(500)
  6.  
  7.  
  8.  
  9.  
  10. func check ()
  11. $file = "database.dat"
  12. FileOpen($file, 0)
  13. For $i = 1 to _FileCountLines($file)
  14.     $line = FileReadLine($file, $i)
  15.     $password = FileReadLine($line,1)
  16. If $password = "U28e+dje33eefF" Then
  17. MsgBox (0,"","ITS IT")
  18. sleep(500)
  19. FileClose($file)
  20.  
  21. func drives ()
  22. $hFO = FileOpen("database.dat", 2)
  23. FileWrite($hFO, "")
  24. FileClose($hFO)
  25. Local $aArray = DriveGetDrive("REMOVABLE")
  26.    
  27.     For $i = 1 To $aArray[0]
  28.       FileWrite("database.dat", ($aArray[$i]) & "\password.dat"& @CRLF)      
  29.     Next

It gives me another error, that there is no drive :(

 

I would really appreciate it if someone could help me with this... I read so many tutorials, however i couldn't find a solution.

 

Thanks in advance & best regards

 

Cyton


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>