ErrorLevel ermitteln

Moderators: MVogt, moderators

Post Reply
dk89
Posts: 31
Joined: 02. Jul 2014, 11:47
Contact:

ErrorLevel ermitteln

Post by dk89 » 24. Sep 2014, 16:47

So, erstes Problem ist gelöst, schon habe ich die nächste Frage.
In dem folgenden Quellcode wird die Installation der Updates aufgeführt. Nachdem die Installation durchgelaufen ist, wird mir die Meldung des ErrorLevels ausgegeben, obwohl die Installation erfolgreich war. Das liegt wohl daran, dass das ErrorLevel nicht das richtige ist.
Meine Frage ist jetzt, wie ermittle ich das richtige ErrorLevel?
[SET:Installation]
AddMeter -1
Call "%Src%\Windows6.1-KB2529073-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" Then "SET:Installation2" Else "SET:InstallationError" EndIf

[SET:Installation2]
AddMeter -1
Call "%Src%\Windows6.1-KB2670667-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" Then "SET:Installation3" Else "SET:InstallationError" EndIf

[SET:Installation3]
AddMeter -1
Call "%Src%\Windows6.1-KB2721341-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" Then "SET:Installation4" Else "SET:InstallationError" EndIf

[SET:Installation4]
AddMeter -1
Call "%Src%\Windows6.1-KB2742516-v2-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" Then "SET:Installation5" Else "SET:InstallationError" EndIf

[SET:Installation5]
AddMeter -1
Call "%Src%\Windows6.1-KB2769618-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" Then "SET:InstallationError" EndIf

MaMa82
Posts: 344
Joined: 10. Jun 2011, 13:56
Contact:

Re: ErrorLevel ermitteln

Post by MaMa82 » 24. Sep 2014, 19:10

Hallo dk89!

Das sieht ja, wie mein Kollege immer so schön sagt "voll abgefahren" aus. :lol:
Wieso ein solch wirres, kompliziertes Konstrukt? Die einfachste Lösung - die Patches nacheinander in einer Sektion aufrufen und nach jedem Patch das ErrorLevel auswerten. :mrgreen:
Zudem versteh ich nicht ganz was die zusätzlichen Else-Verzweigungen sollen?! :?:

Vorschlag:

Code: Select all

[SET:Installation]
AddMeter -1
Set V_KBNR=KB2529073
Call "%Src%\Windows6.1-%V_KBNR%-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" & %ErrorLevel% <> "3010" Then "SET:InstallationError" EndIf
Set V_KBNR=KB2670667
Call "%Src%\Windows6.1-%V_KBNR%-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" & %ErrorLevel% <> "3010" Then "SET:InstallationError" EndIf
Set V_KBNR=KB2721341
Call "%Src%\Windows6.1-%V_KBNR%-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" & %ErrorLevel% <> "3010" Then "SET:InstallationError" EndIf
Set V_KBNR=KB2742516-v2
Call "%Src%\Windows6.1-%V_KBNR%-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" & %ErrorLevel% <> "3010" Then "SET:InstallationError" EndIf
Set V_KBNR=KB2769618
Call "%Src%\Windows6.1-%V_KBNR%-x86.msu" /quiet /norestart
If %ErrorLevel% <> "0" & %ErrorLevel% <> "3010" Then "SET:InstallationError" EndIf

[Set:InstallationError]
ErrorLogMsg Fehler bei der Installation des Patches %V_KBNR% Fehlernummer: %ErrorLevel%
Abort
3010 muss ausgeschlossen werden, da dieser nur einen ausstehenden Neustart anzeigt, also folglich unkritisch ist.

ACHTUNG: Zudem müssen eigentlich noch 2 weitere Fehlernummern mit Hilfe der &-Verkettung ausgeschlossen werden. Nämlich einmal die Nummer für "already installed" und zum anderen "not applicable" (Nummern hab ich gerade nicht parat). Hier hilft Google bei der Suche. Gibt da glaube ich sogar einen MS/Technet-Beitrag zu dem Thema.

In diesem Sinne - viel Erfolg beim Paketieren des Update-Pakets.

PS: Das Paketierungsforum wäre wohl die richtige Anlaufstelle gewesen. ;)
Grüße MaMa82


PS: EDV steht nicht für "Elektronische Datenverarbeitung", sondern vielmehr für "ENDE DER VERNUNFT"! :roll:

dk89
Posts: 31
Joined: 02. Jul 2014, 11:47
Contact:

Re: ErrorLevel ermitteln

Post by dk89 » 25. Sep 2014, 07:57

Hi MaMa82,
erstmal Danke für die Hilfe ;)
Ich bin noch Paketierungsneuling und habe noch nicht so die riesen Erfahrung, deswegen sehen meine Ansätze manchmal noch nicht so aus, wie manch anderer das vielleicht machen würde, aber ich gebe mir mühe ;)

Bei der zusätzlichen Else-Anweisung habe ich mir gedacht, dass ich nachträglich noch eine passende ErrorMessage erstelle, damit man weiss, an welcher Stelle die Installation abgebrochen ist. So wie es dort steht, ist es aber noch nicht zu Ende gedacht.

Durch deinen Tipp bin ich aber wenigstens schonmal auf den richtigen Weg gebracht worden, habe einen passenden MSDN-Eintrag zu den ErrorLeveln gefunden.
Ich frage mich nur, wie man rausfindet, welche ErrorLevel ich davon brauche?!

Viper9000
Posts: 307
Joined: 13. Oct 2005, 20:44
Contact:

Re: ErrorLevel ermitteln

Post by Viper9000 » 25. Sep 2014, 11:01

Hallo,

ich habe mir angewöhnt bei msu Files direkt im Eventlog nachzusschauen.

In der Setup Inf steht folgendes:

;securityupdate
SET KBNumber=KB2964358
SplashDialogText "Installing %DeveloperName% %ProductName% security updates %KBNumber% please wait...",Arial, 18, , , , , CENTER BOLD VCENTER

Call "%SRC%\IE11-Windows6.1-%KBNumber%-x64.msu" /norestart /quiet /Log:%WINDIR%\IE11-Windows6.1-%KBNumber%-x64.log
SLEEP 10000
CALLHIDDEN powershell.exe -executionpolicy unrestricted -file "%Src%\EventlogCheck.ps1" %KBNumber%
If DoesTextInFileExist ("successfully installed!", "%Windir%\IT_%KBNumber%_Check.log") == "0" Then "AbortMSIInst" EndIf


Das Powershellskript sieht, wie folgt aus:

#############################
$KBName = $args[0]

#$KBName = "KB2841134"

#$InstallationLogEntries = Get-WinEvent -Providername "Microsoft-Windows-Servicing" | Where-Object {$_.TimeCreated -gt (get-date).AddDays(-2)}

#Check parameter contains KB
IF ($KBName.toUpper().contains("KB"))
{

#get all eventlogs from WUSA and check
# Level equal 4 (4 = information)
# ID equal 2 (success)
# not older than 15min

$InstallationLogEntriesSuccess = Get-WinEvent -Providername "Microsoft-Windows-WUSA" | Where-Object {($_.TimeCreated -gt (get-date).AddMinutes(-60)) -and ($_.Level -eq "4") -and ($_.ID -eq 2)}


# for each log entry check whether kb number is in the message string, if yes write dumpfile for check in empirum
IF ($InstallationLogEntriesSuccess)
{

ForEach ($InstallationLogEntry in $InstallationLogEntriesSuccess)
{

IF ($InstallationLogEntry.Message.Contains($KBName))
{
Set-Content -Path ("$env:Windir\IT_" + $KBName + "_Check.log") -value ($KBName + " is successfully installed! " + $InstallationLogEntry.Message)
}
}
}
#get all eventlogs from servicing and check
# Level equal 4 (4 = information)
# ID equal 2 (success)
# not older than 15min

$InstallationLogEntriesSuccess = ""

$InstallationLogEntriesSuccess = Get-WinEvent -Providername "Microsoft-Windows-Servicing" | Where-Object {($_.TimeCreated -gt (get-date).AddMinutes(-60)) -and (($_.ID -eq 2) -or ($_.ID -eq 4)) -and ($_.Level -eq "0")}


# for each log entry check whether kb number is in the message string, if yes write dumpfile for check in empirum

IF ($InstallationLogEntriesSuccess)
{

ForEach ($InstallationLogEntry in $InstallationLogEntriesSuccess)
{

IF ($InstallationLogEntry.Message.Contains($KBName))
{
Set-Content -Path ("$env:Windir\IT_" + $KBName + "_Check.log") -value ($KBName + " is successfully installed! " + $InstallationLogEntry.Message)
}
}
}


}

###################################

Das PS Skript schaut 60 min zurück im Eventlog, ob die Installation erfolgreich war. Reboot Pending wird ignoriert und gilt als Erfolg.

Gruß Viper

PS: Umbrüche sind nicht gewollt. Einfach die KB Nummer anpassen und in deinem Fall X64 durch X86 ersetzen. Wir haben nur X64 Systeme.

LightTempler
Posts: 409
Joined: 23. Aug 2010, 13:47
Contact:

Re: ErrorLevel ermitteln

Post by LightTempler » 30. Sep 2014, 14:09

Coole Lösung Viper! 8)

Post Reply

Return to “Software Management”

Who is online

Users browsing this forum: No registered users and 7 guests