EmilyLove Posted September 21, 2016 Share Posted September 21, 2016 (edited) So here's my code. I am downloading a file using chrome (because inetget doesnt work). I want my code to move the file elsewhere when it is done downloading. $Drive="C:\" Do $hVipre = FileFindFirstFile(@UserProfileDir & "\Downloads\VIPRERescue*") Do $Vipre = FileFindNextFile($hVipre) If @error = 1 Then FileClose($hVipre) $Vipre = "" ExitLoop EndIf Until @error <> 1 AND $Vipre <> "" Until FileExists(@UserProfileDir & "\Downloads\" & $Vipre) = 1 FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1) It tries to move a file that is still downloading and thus causes problems. I'm fairly new to searching files so any help would be greatly appreciated. ~Jeff Edited September 21, 2016 by BetaLeaf Solution at https://www.autoitscript.com/forum/topic/184663-solved-filefindnextfile-grabbing-unintended-file/?do=findComment&comment=1326452 Link to comment Share on other sites More sharing options...
Xandy Posted September 21, 2016 Share Posted September 21, 2016 (edited) Wait till the file is a certain size. If you can send the file size from Chrome, then you can move when the file is that size. Another good way if you cannot get the file size from Chrome, is to detect the file and note it's size. If the file stays the same size for like 40 seconds or something then you can assume the file is ready to be moved. If the file size changes reset the counter. I've done this with FTP but not Chrome Edited September 21, 2016 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
PACaleala Posted September 21, 2016 Share Posted September 21, 2016 Au3 help file: _WinAPI_FileInUse Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 4 hours ago, PACaleala said: Au3 help file: _WinAPI_FileInUse I like your answer best but unfortunately, it still moves the file before the download is complete. Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 (edited) That was weird. I was quoting Xandy but when I submitted the post, instead of posting what I actually typed, it put what I post last, resulting in a duplicate double post. I've never seen any forum do this before. New Feature? lol. 4 hours ago, PACaleala said: Edited September 21, 2016 by BetaLeaf Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 5 hours ago, Xandy said: Wait till the file is a certain size. If you can send the file size from Chrome, then you can move when the file is that size. Another good way if you cannot get the file size from Chrome, is to detect the file and note it's size. If the file stays the same size for like 40 seconds or something then you can assume the file is ready to be moved. If the file size changes reset the counter. I've done this with FTP but not Chrome Unfortunately, I don't this this would help. The script is grabbing files like "Unconfirmed 868445.crdownload", which are undownloaded files. They don't even match the search string. What's going on here? I only want the completed files im searching for. Link to comment Share on other sites More sharing options...
pluto41 Posted September 21, 2016 Share Posted September 21, 2016 (edited) #include <MsgBoxConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue.exe" Local $sSearchFile = "VIPRERescue.exe" Local $sFileName, $hSearch Do $hSearch = FileFindFirstFile ($sSearchDir & $sSearchFile) $sFileName = FileFindNextFile ($hSearch) Sleep (500) Until $sFileName = $sSearchFile FileClose ($hSearch) Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName) If the filename always is "VIPRERescue.exe" something like the code above would work. edit: Perhaps FileClose() should go in the Do / Until loop. I overlooked that. Edited September 21, 2016 by pluto41 Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 I wouldn't be use find file if that was true. Unfortunately the number changes with each release. Link to comment Share on other sites More sharing options...
pluto41 Posted September 21, 2016 Share Posted September 21, 2016 #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" Local $sFileName, $hSearch Do $hSearch = FileFindFirstFile ($sSearchDir) $sFileName = FileFindNextFile ($hSearch) FileClose ($hSearch) Sleep (500) Until StringRegExp ( $sFileName, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ; Find VIPRERescue / Number / .exe Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName) Then Something like this? Added StringRegExp () Function. Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 8 minutes ago, pluto41 said: #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" Local $sFileName, $hSearch Do $hSearch = FileFindFirstFile ($sSearchDir) $sFileName = FileFindNextFile ($hSearch) FileClose ($hSearch) Sleep (500) Until StringRegExp ( $sFileName, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ; Find VIPRERescue / Number / .exe Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName) Then Something like this? Added StringRegExp () Function. I'm terrible with regular expressions. I changed my code to this but it is still grabbing incompleted files. Do $hVipre = FileFindFirstFile(@UserProfileDir & "\Downloads\VIPRERescue*.exe") Do $Vipre = FileFindNextFile($hVipre) If @error = 1 Then FileClose($hVipre) $Vipre = "" ExitLoop EndIf Until stringRegExp($Vipre,'(?i)VIPRERescue\d+.exe',$STR_REGEXPMATCH) = 1 Until FileExists(@UserProfileDir & "\Downloads\" & $Vipre) = 1 ConsoleWrite("Moving VipreRescue" & @CRLF) FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1) There is something wrong with my FileFindNextFile Loop. It is escaping the loop when it detects something I didn't search for. It should only escape the loop when it finds the completed file, something I am searching for. Link to comment Share on other sites More sharing options...
pluto41 Posted September 21, 2016 Share Posted September 21, 2016 #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" ;Local $sSearchDir = "C:\Temp\Downloads\VIPRERescue*" Local $Drive = "C:\" do $hVipre = FileFindFirstFile($sSearchDir) Do $Vipre = FileFindNextFile($hVipre) If @Error Then Exitloop Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ConsoleWrite("Moving VipreRescue" & @CRLF) FileClose ($hVipre) FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1) This works for me in a test [c:\temp\..]. I think you are close to a solution for the problem. EmilyLove 1 Link to comment Share on other sites More sharing options...
Danyfirex Posted September 21, 2016 Share Posted September 21, 2016 Hello. Just a question why InetGet does no work? Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 30 minutes ago, pluto41 said: #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" ;Local $sSearchDir = "C:\Temp\Downloads\VIPRERescue*" Local $Drive = "C:\" do $hVipre = FileFindFirstFile($sSearchDir) Do $Vipre = FileFindNextFile($hVipre) If @Error Then Exitloop Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ConsoleWrite("Moving VipreRescue" & @CRLF) FileClose ($hVipre) FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1) This works for me in a test [c:\temp\..]. I think you are close to a solution for the problem. This worked for me as well. Thank you very much @pluto41. Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 2 minutes ago, Danyfirex said: Hello. Just a question why InetGet does no work? Saludos Because the links I have to download the programs with are as follow: "http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/81/" "http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/82/" "http://www.bleepingcomputer.com/download/combofix/dl/12/" "http://www.bleepingcomputer.com/download/adwcleaner/dl/125/" "http://go.vipreantivirus.com/?linkid=1605" "https://www.piriform.com/ccleaner/download/portable/downloadfile" I do virus removal and I always want to have the most up to date tools when I go out for a job. These links either go to a loading page or redirect to the actual download. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 21, 2016 Share Posted September 21, 2016 I think something like this could work. Local $oHttp = ObjCreate("winhttp.winhttprequest.5.1") $oHttp.Option(6) = False $oHttp.open("GET","http://go.vipreantivirus.com/?linkid=1605") $oHttp.Send() Local $sHotLink=$oHttp.GetResponseHeader("Location") ConsoleWrite($sHotLink & @CRLF) ;~ InetGet( $sHotLink,"Somefile.temp") Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 2 minutes ago, Danyfirex said: I think something like this could work. Local $oHttp = ObjCreate("winhttp.winhttprequest.5.1") $oHttp.Option(6) = False $oHttp.open("GET","http://go.vipreantivirus.com/?linkid=1605") $oHttp.Send() Local $sHotLink=$oHttp.GetResponseHeader("Location") ConsoleWrite($sHotLink & @CRLF) ;~ InetGet( $sHotLink,"Somefile.temp") Saludos Ah, Com Objects. Another thing I'm horrible at. Where did you learn to use these? I have a working solution I'm happy with. I'm not going to be able to get all of those to work without spending hours working on a script. I've already dumped more time into it then I would have saved. Still, would love to know where you learned to use the $oHttp com objects. Will be useful to know in future projects. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 21, 2016 Share Posted September 21, 2016 Just gooling and checking code snippets. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
bloopie Posted September 21, 2016 Share Posted September 21, 2016 (edited) 6 hours ago, BetaLeaf said: Because the links I have to download the programs with are as follow: "http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/81/" "http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/82/" "http://www.bleepingcomputer.com/download/combofix/dl/12/" "http://www.bleepingcomputer.com/download/adwcleaner/dl/125/" "http://go.vipreantivirus.com/?linkid=1605" "https://www.piriform.com/ccleaner/download/portable/downloadfile" I do virus removal and I always want to have the most up to date tools when I go out for a job. These links either go to a loading page or redirect to the actual download. ---> I know this is off topic, but: You are likely aware that Combofix has not been updated in some time, and also will not work with later operating systems? :wink: bloopie Edited September 21, 2016 by bloopie fixed typo EmilyLove 1 Malware Response Instructor @ BC Link to comment Share on other sites More sharing options...
EmilyLove Posted September 21, 2016 Author Share Posted September 21, 2016 I am indeed aware of this. I use a loader also made with autoit that ensure it isn't ran in incompatible systems. I wasn't sure if it was still be updated only for older or or not tho. Link to comment Share on other sites More sharing options...
bloopie Posted September 21, 2016 Share Posted September 21, 2016 Last update I see (on my end) is June 2, 2015, and I believe we are still the only official download link. Malware removal was lots of fun back in 2012 when rootkits were running rampant, and I wrote hundreds of CFScripts then...but malware is different these days (cryptolocker and the like) and CF is not updated to deal with infections out there today. Probably best to remove CF from your toolbox. CF also makes changes to Operating System settings in its routines...some may be unwanted (like setting IE as default browser...and many others). bloopie Malware Response Instructor @ BC Link to comment Share on other sites More sharing options...
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