Sign in to follow this  
Followers 0
Bigbear

Stinger file downloader & executer

4 posts in this topic

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?

Thanks

StingerFileDownloaderRunner.au3

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Like this maybe? Thanks for using my Functions btw :unsure:

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 by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

hi,

@Bigbear: A bit shorter and a bit more modular, with some minor tweaks here and there:

#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   ;==>__ByteSuffix
PS: 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 :unsure:

-smartee

Share this post


Link to post
Share on other sites

No problem at all! It wasn't such a major change :unsure: I also liked the SRE you used, very clever.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0