McAfee SDATxxxx.exe download Skript

  • Hallo,

    ich habe da ein kleines Skript geschrieben, dass die aktuelle SDATxxxx.exe von der McAfee Seite herunterlädt.
    Ich denke da gibt es noch ordentlich Verbesserungsmöglichkeiten, z. B.

    • Code von Bugs befreien :)
    • hinzufügen weiterer Kommandozeilenparameter, damit eine INI nicht unbedingt nötig ist
    • Errorhandling
    • vernünftiges Logging
    • vollständig unbeaufsichtigter Modus, damit man es auch per Scheduler (oder AT-Job) laufen lasse kann
    • etc.

    Vielleicht kann es ja jemand hier gebrauchen...

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ;
    ; Description: Download of current SDATxxxx.exe files from McAfee page
    ; via HTTP (FTP is not allowed in some companies...)
    ;
    ; Author(s): ahe
    ; Version: 1.0.0.0
    ; Date: 26.06.2009
    ;
    ; Filename: McAfee_SDAT_Download.au3
    ; EXE name: McAfee_SDAT_Download.exe
    ;
    ;===============================================================================
    ; The script download the update.ini file from McAfee site, scan the entry for SDATxxxx.exe version
    ; and download the grabbed exe.
    ; In INI file CONF_SDAT_UPD.ini all specific pathes are stored, if McAfee changed something, you can
    ; change the entries too.
    ;===============================================================================
    ; Parameters from INI file:
    ; $update_site_url Path to update.ini on download page
    ; $sdat_url Base path to sdatxxxx.exe
    ; $update_ini_file Local store path to INI file
    ; $dest_sdat_path Local store path for sdatxxxx.exe

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $INI = @ScriptDir & "\CONF_SDAT_UPD.ini"

    [/autoit] [autoit][/autoit] [autoit]

    $INIFILE= 'CONV_SDAT_UPD.INI - example:' & @CRLF & @CRLF
    $INIFILE= $INIFILE & '________________________________________________________________________________' & @CRLF
    $INIFILE= $INIFILE & '[SDATURL]'& @CRLF
    $INIFILE= $INIFILE & '; Path to update.ini on download page'& @CRLF
    $INIFILE= $INIFILE & 'UPDATE_INI_URL="http://download.nai.com/products/datfiles/4.x/nai/update.ini"' & @CRLF
    $INIFILE= $INIFILE & '; Base path to sdatxxxx.exe'& @CRLF
    $INIFILE= $INIFILE & 'SDAT_URL="http://download.nai.com/products/licensed/superdat/english/intel/"'
    $INIFILE= $INIFILE & '[SDATPATH]'& @CRLF
    $INIFILE= $INIFILE & '; Local store path to INI file'& @CRLF
    $INIFILE= $INIFILE & 'UPDATE_INI_PATH="c:\temp\nai\update.ini"'& @CRLF
    $INIFILE= $INIFILE & '; Local store path for sdatxxxx.exe'& @CRLF
    $INIFILE= $INIFILE & 'DEST_SDAT_PATH="c:\temp\nai"'& @CRLF
    $INIFILE= $INIFILE & '________________________________________________________________________________' & @CRLF

    [/autoit] [autoit][/autoit] [autoit]

    $helpmsg = "Correct installation parameters:" & @CRLF
    $helpmsg = $helpmsg & @TAB & "No parameter and no ini config file!" & @TAB & "The embedded values are used... (s. switch -e or /e)" & @CRLF
    $helpmsg = $helpmsg & @TAB & "-INI YES " & @TAB & @TAB & "Use SDAT_UPD.ini in current directory to find the path to SDATxxxx.exe" & @CRLF
    $helpmsg = $helpmsg & @TAB & "-INI NO " & @TAB & @TAB & "Search SDATxxxx.exe in standard path" & @CRLF
    $helpmsg = $helpmsg & @TAB & "-PATH <path> " & @TAB & "Use the given path in the brackets <> to search SDATxxxx.exe" & @CRLF
    $helpmsg = $helpmsg & @TAB & "-i or /i" & @TAB & "Overview about a correct CONF_SDAT_UPD.INI file." & @CRLF & @CRLF
    $helpmsg = $helpmsg & @TAB & "This help: ?, -?, /?, h, -h, /h"

    [/autoit] [autoit][/autoit] [autoit]

    $helpmsg2 = "List embedded parameters:" & @CRLF
    $helpmsg2 = $helpmsg2 & @TAB & "Path to update.ini on download page:" & @TAB & 'UPDATE_INI_URL="http://download.nai.com/products/datfiles/4.x/nai/update.ini"' & @CRLF
    $helpmsg2 = $helpmsg2 & @TAB & "Base path to SDATxxxx.exe:" & @TAB & @TAB & 'SDAT_URL="http://download.nai.com/products/licensed/superdat/english/intel/"' & @CRLF
    $helpmsg2 = $helpmsg2 & @TAB & "Local store path to INI file:" & @TAB & @TAB & 'UPDATE_INI_PATH="c:\temp\nai\update.ini"' & @CRLF
    $helpmsg2 = $helpmsg2 & @TAB & "Local store path for SDATxxxx.exe:" & @TAB & 'DEST_SDAT_PATH="c:\temp\nai"' & @CRLF & @CRLF
    $helpmsg2 = $helpmsg2 & @TAB & @TAB & "Help: ?, -?, /?, h, -h, /h"

    [/autoit] [autoit][/autoit] [autoit]

    if $CmdLine[0]=0 then
    if FileExists($INI) Then
    $update_site_url = IniRead($INI, "SDATURL", "UPDATE_INI_URL","NotFound")
    $sdat_url = IniRead($INI, "SDATURL", "SDAT_URL","NotFound")
    $dest_sdat_path = IniRead($INI, "SDATPATH", "DEST_SDAT_PATH","NotFound")
    $update_ini_file = IniRead($INI, "SDATPATH", "UPDATE_INI_PATH","NotFound")

    if $update_site_url="NotFound" or $sdat_url="NotFound" or $dest_sdat_path="NotFound" or $update_ini_file="NotFound" Then
    MsgBox(0,"Error", "Not all entries in update.ini exist! Check values in CONF_SDAT_UPD.ini! "& @CRLF & @CRLF & $INIFILE)
    Exit 90
    EndIf
    Else
    ; use standard parameters, could be quite old... :)
    $update_site_url="http://download.nai.com/products/datfiles/4.x/nai/update.ini"
    $sdat_url="http://download.nai.com/products/licensed/superdat/english/intel/"
    $update_ini_file="c:\temp\nai\update.ini"
    $dest_sdat_path="c:\temp\nai"
    EndIf
    Else
    if $CmdLine[0]>0 then
    Select
    Case $CmdLine[1]="?" or $CmdLine[1]="-?" or $CmdLine[1]="/?" or $CmdLine[1]="h" or $CmdLine[1]="-h"or $CmdLine[1]="/h"
    MsgBox(0, "Installation parameter", $helpmsg)
    Exit 10
    case StringUpper($CmdLine[1])="-E" or StringUpper($CmdLine[1])="/E"
    MsgBox(0, "Installation parameter", $helpmsg2)
    Exit 10
    case StringUpper($CmdLine[1])="-I" or StringUpper($CmdLine[1])="/I"
    MsgBox(0, "INI configuration", $INIFILE)
    Exit 10
    ;Case StringUpper($CmdLine[1])="UPDATE_INI_URL" ; Command line or not Command line that's here the question...

    Case Else
    exit
    EndSelect
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;$update_site_url="http://download.nai.com/products/datfiles/4.x/nai/update.ini"
    if $update_ini_file = "NotFound" Then
    $update_ini_file=@TempDir & "\nai\update.ini"
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    if $dest_sdat_path = "NotFound" Then
    $dest_sdat_path=@TempDir & "\nai"
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; check if directory for update.ini exist and if update.ini exist delete it...
    if FileExists($dest_sdat_path) <> 1 then
    DirCreate($dest_sdat_path)
    Else
    if FileExists($dest_sdat_path &"\update.ini") then FileDelete($dest_sdat_path &"\update.ini")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; download standard update.ini from McAfee page and save it in $update_ini_file
    InetGet($update_site_url, $update_ini_file, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; wait a bit, otherwise IniRead won't find a update.ini to read...
    Sleep(5000)

    [/autoit] [autoit][/autoit] [autoit]

    ; get name of current SDATxxxx.exe from update.ini
    $SDAT_name=IniRead($update_ini_file, "SuperDat-IA32", "FileName", "NotFound")
    If $SDAT_name="NotFound" Then
    MsgBox(0,"Error", "Error: No SDAT entry in update.ini")
    Exit 92
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;MsgBox(0, "SDATName", $SDAT_name)
    ;$SDAT_url = "http://download.nai.com/products/licensed/superdat/english/intel/" & $SDAT_name
    $Full_SDAT_url = $sdat_url & $SDAT_name
    ; check the size of the file
    $size=InetGetSize($Full_SDAT_url)
    ; download SDATxxxx.exe and save the file to $dest_sdat_path
    InetGet($Full_SDAT_url, $dest_sdat_path & "\" & $SDAT_name, 1, 1)
    $mypercent= $size/100 ; one percent of the size

    [/autoit] [autoit][/autoit] [autoit]

    While @InetGetActive
    $view = (@InetGetBytesRead / $mypercent)
    $view = Round($view)

    TrayTip("Downloading " & $SDAT_name, "MBytes = " & Round(@InetGetBytesRead/1048576,2) & @CRLF & "Percent: " & $view, 10, 16)
    Sleep(250)
    Wend

    [/autoit] [autoit][/autoit] [autoit]

    ;MsgBox(0, "Download finished! MBytes read: ", Round(@InetGetBytesRead/1048576,2))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Execute the close environment when the script ends.
    Func onAutoItExit()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GetParameters($s_ParamName)
    ;Create Param Name
    Local $s_RealParamName = "-" & $s_ParamName

    For $i = 1 To $CmdLine[0] Step 1
    If $s_RealParamName = $CmdLine[$i] Then
    If $i + 1 <= $CmdLine[0] Then
    Return $CmdLine[$i + 1]
    EndIf
    EndIf
    Next
    Return ""
    EndFunc ;==>_GetParameters

    [/autoit]


    mfg
    Axel

    There exist 10 different kind of people on earth.
    Those who understand binary, and those who don't.

    Einmal editiert, zuletzt von ahe (28. Juni 2009 um 22:27)

  • Da habe ich wohl vergessen die Dateien anzuhängen...

    Die CONF_SDAT_UPD.ini.txt Datei muss nur entsprechend als CONF_SDAT_UPD.ini im ScriptDir abgespeichert werden...

    Axel

    There exist 10 different kind of people on earth.
    Those who understand binary, and those who don't.

    Einmal editiert, zuletzt von ahe (28. Juni 2009 um 22:29)

  • Nett gemacht :thumbup:

    aber das geöhrt ins forum: Skripte oder

    hast du bezuglich fragen und brauchst hilfestellung :?: :whistling:

  • Danke :D

    Nun ein paar Fragen hätte ich schon...
    1.
    Ursprünglich wollte ich die meldungen nicht in einer Message Box ausgeben, sondern auf der Kommandozeile. Allerdings fände ich es auch schön, wenn die Anwendung erkennt, ob sie entweder von der Kommandozeile bzw. per AT-Job bzw. aus einer Batch heraus gestartet wird, oder aber per Doppelklick über die GUI...

    Wenn ich den Hinweis von Xeno allerdings richtig verstanden habe, habe ich nur die Wahl, entweder Kommandozeile, oder GUI...
    ( [ offen ] Statusausgaben in Kommandozeile plotten), das wäre schade...

    2.
    Ein wenig habe ich ja mit einfachen Parameteraufrufen begonnen, nur würde ich das ggfs. noch etwas ausweiten, wenn ich wüßte, ob der Weg den ich da gegangen bin sinnvoll ist, oder ob es vielleicht eine geschicktere Alternative gibt...

    3.
    Die "Abfrage-Struktur" fängt derzeit nicht den Wunsch ab, z. B. einen INI-Wert durch einen Kommandozeilen-Parameter zu überschreiben. D. h. sobald ein entsprechender Kommandozeilen-Parameter gesetzt wird, wird nicht der Wert aus der INI gelesen, sondern der, der als Parameter and der Kommandozeile angegeben wurde:
    Die folgende Zeile könnte den Pfad für die update.ini, der in der CONF_SDAT_UPD.ini ignorieren und einen eigenen nehmen

    Code
    -INI YES -UPDATE_INI_PATH=D:\nai\update.ini

    Da ich noch nicht so firm bin, die Übergabeparameter auszuwerten, habe ich bislang auf solche Dinge verzichtet...

    mfg
    Axel

    There exist 10 different kind of people on earth.
    Those who understand binary, and those who don't.

  • Weist du was mir fehlt an deinem skript .

    Wen ich grad die software downloade und aus mache , das er nich weiter macht sondern wieder von neu anfengt :D

    wird aber schwierig zu skripten denke ich ma ^^

    Einmal editiert, zuletzt von FunH@cker (28. Juni 2009 um 23:31)