Bigbear Posted May 11, 2011 Posted May 11, 2011 This is my first Autoit code that I created. Basically, it finds the latest stinger version of code, "stinger101xxxxx", downloads it and then runs it. I borrowed some work by guinness to download it. My question for the forum, is there a better way to find the latest version? ThanksStingerFileDownloaderRunner.au3
guinness Posted May 11, 2011 Posted May 11, 2011 (edited) Like this maybe? Thanks for using my Functions btw Global $iVersion = _GetStingerVersion() ConsoleWrite($iVersion & @CRLF) ConsoleWrite( _GetStingerURL($iVersion) & @CRLF) Func _GetStingerURL($iVersion) Return "http://downloadcenter.mcafee.com/products/mcafee-avert/stinger" & $iVersion & ".exe" EndFunc ;==>_GetStingerURL Func _GetStingerVersion() Local $aReturn, $bRead, $sRead $bRead = InetRead("http://www.mcafee.com/us/downloads/free-tools/stinger.aspx") $sRead = BinaryToString($bRead) $aReturn = StringRegExp($sRead, '(?s)(?i)<strong>Build Number:</strong>(.*?)<br /><strong>', 3) If @error Then Return SetError(1, 0, -1) EndIf Return StringReplace(StringStripWS($aReturn[0], 9), ".", "") EndFunc ;==>_GetStingerVersion Edited May 11, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
smartee Posted May 11, 2011 Posted May 11, 2011 hi, @Bigbear: A bit shorter and a bit more modular, with some minor tweaks here and there:expandcollapse popup#include <Inet.au3> $DefaultDir = @DesktopDir & "\Batch" $StingerDownloadPage = "http://www.mcafee.com/apps/free-tools/termsofuse.aspx?url=/us/downloads/free-tools/stinger.aspx" $McAfeeStingerArr = StringRegExp(_INetGetSource($StingerDownloadPage), "http://downloadcenter\.mcafee\.com/products/mcafee-avert/stinger[\d]+\.exe", 1) _DownRun($McAfeeStingerArr[0], "/ADL /GO /LOG /SILENT", $DefaultDir) ; If you wanted to download and run the latest MSERT _DownRun("http://definitionupdates.microsoft.com/download/definitionupdates/safetyscanner/x86/msert.exe", "/Q /F:Y", $DefaultDir) Func _DownRun($sURL, $sParams, $sDir) If Not (FileExists($sDir)) And Not (DirCreate($sDir)) Then Return SetError(1, 0, -1) Return ShellExecuteWait(_InetGetProgress($sURL, $sDir), $sParams, $sDir) EndFunc ;==>_DownRun ;Download the latest file ;Author ........: guinness Func _InetGetProgress($sURL, $sDirectory = @ScriptDir) Local $hDownload, $iBytesRead, $iFileSize, $iPercentage, $sFile, $sProgressText, $sFullPath $sFile = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFile) EndIf If StringRight($sDirectory, 1) <> "\" Then $sDirectory = $sDirectory & "\" EndIf $sFullPath = $sDirectory & $sFile If FileExists($sFullPath) Then Return $sFullPath $iFileSize = InetGetSize($sURL, 1) $hDownload = InetGet($sURL, $sFullPath, 0, 1) If @error Then Return SetError(1, 0, $sFile) EndIf ProgressOn("", "") While InetGetInfo($hDownload, 2) = 0 $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & __ByteSuffix($iBytesRead) & " Of " & __ByteSuffix($iFileSize) ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading " & $sFile) Sleep(100) WEnd InetClose($hDownload) ProgressOff() Return $sFullPath EndFunc ;==>_InetGetProgress Func __ByteSuffix($iBytes) Local $A, $aArray[6] = ["B", "KB", "MB", "GB", "TB", "PB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes) & " " & $aArray[$A] EndFunc ;==>__ByteSuffixPS: I am using ShellExecuteWait(), in case you want to run multiple tools in succession. @guinness: Nice work on those functions , I made a couple minor changes to them in my solution though, mainly to suit the _DownRun() function, hope you dont mind -smartee
guinness Posted May 11, 2011 Posted May 11, 2011 No problem at all! It wasn't such a major change I also liked the SRE you used, very clever. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
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