Opsi Startup lässt sich nicht deaktivieren

Antworten
leonardo
Beiträge: 30
Registriert: 03 Mai 2016, 22:51

Opsi Startup lässt sich nicht deaktivieren

Beitrag von leonardo »

Hallo,

ich bin gerade dabei die Funktionalität "Install By Shutdown" auszutesten und bin dabei auf ein Problem gestoßen. Das ausführen von Installationen lässt sich beim opsi Startup nicht deaktivieren, wenn die Ausführung auf "Always" steht.

Die Deaktivierung erfolgte über den Parameter

Code: Alles auswählen

opsiclientd.event_gui_startup.active = false
Das Thema wurde bereits in folgendem Thread erörtert viewtopic.php?f=7&t=6720.

Versionen:
opsi Server = 4.0.7.45
opsi-client-agent = 4.0.7.23-4
opsi-winst = 4.12.0.7-1

Viele Grüße
Leonardo
Benutzeravatar
ueluekmen
uib-Team
Beiträge: 1939
Registriert: 28 Mai 2008, 10:53

Re: Opsi Startup lässt sich nicht deaktivieren

Beitrag von ueluekmen »

Hi Leonardo,

ich würde prüfen, ob es das selbe Problem ist. Siehst du bei dir auch installation_pending? Ich habe mal kurz geschaut, vor drei Jahren gabe es einen Fix, der mit 4.0.5.2-1 gefixed und veröffentlicht (opsiclientd Version 4.0.82).

Bisher haben wir das nicht mehr gemeldet bekommen, kann aber noch kaputt oder noch nicht vollständig gefixed sein. Macht dein always Paket vielleicht selbst einen Reboot?
opsi support - uib gmbh
For productive opsi installations we recommend support contracts.
http://www.uib.de
leonardo
Beiträge: 30
Registriert: 03 Mai 2016, 22:51

Re: Opsi Startup lässt sich nicht deaktivieren

Beitrag von leonardo »

Ich hänge hier mal das entsprechende Script an, dann können wir uns besser über das Problem unterhalten.

Code: Alles auswählen

encoding=UTF-8
[Actions]
AutoActivityDisplay = true
 
DefVar $ProductId$
DefVar $only_shutdown$
DefVar $winupdate_shutdown$
DefVar $exitcode$
DefVar $win_runmode$
DefVar $act_reboot_counter$
DefVar $max_reboot_counter$

Set $ProductID$ = "WSUS Offline Updater"
Set $only_shutdown$ = GetProductProperty("only_shutdown","false")
Set $winupdate_shutdown$ = GetProductProperty("winupdate_shutdown","false")
Set $max_reboot_counter$ = GetProductProperty("max_reboot_counter", "15")

ShowBitmap "%ScriptPath%\wsusoffline_client.png" $ProductId$

; --- Workflow ---
; Beschreibung der Parameter: http://forums.wsusoffline.net/viewtopic.php?t=2691

; Import Libraries
importLib "function-global.opsiscript"
set $exitcode$ = processCall('powershell Set-ExecutionPolicy RemoteSigned') /64Bit

; Prüfe Rebootflag
set $exitcode$ = function-rebootflag_check($act_reboot_counter$,$max_reboot_counter$)
if ($act_reboot_counter$ INT> $max_reboot_counter$)
   set $act_reboot_counter$ = "0"
   Registry_SaveRebootCounter
   comment "Maximale Anzahl an Neustarts erreicht, act_reboot_counter (Rebootflag) zurueckgesetzt auf 0"
   isSuccess
endif

; Prüfe opsi Aufruf
set $win_runmode$ = function-opsi-start_check("test")
if ($only_shutdown$ = "true")
   if ($win_runmode$ = "shutdown")
      Message "Starte Windows Updates ..."
      set $exitcode$ = shellCall('"%ScriptPath%\..\wsusoffline_depot\client\cmd\DoUpdate.cmd" /updatecpp /updatetsc /instdotnet35 /instdotnet4 /instpsh /instwmf')
   else
      Message "Windows Updates beim Start/Betrieb nicht erlaubt"
   endif
   isSuccess
endif

Message "Starte Windows Updates ..."
set $exitcode$ = shellCall('"%ScriptPath%\..\wsusoffline_depot\client\cmd\DoUpdate.cmd" /updatecpp /updatetsc /instdotnet35 /instdotnet4 /instpsh /instwmf')

; Prüfe Reboot Status
set $exitcode$ = function-exitcode_check($exitcode$,$act_reboot_counter$,$max_reboot_counter$,"true","ImmediateReboot")
set $exitcode$ = function-reboot_check($act_reboot_counter$,"ImmediateReboot")

; Setze Rebbootflag auf Standard
set $act_reboot_counter$ = "0"
Registry_SaveRebootCounter

; Prüfe Windows Shutdown
if ($winupdate_shutdown$ = "true")
   opsiServiceCall_reset_prop_winupdate_shutdown

   Message "Windows herunterfahren ..."
   ExitWindows /ShutdownWanted
endif

; --- Sections ---
[opsiServiceCall_reset_prop_winupdate_shutdown]
"method": "setProductProperty"
"params": [
"wsusoffline",
"winupdate_shutdown",
"false",
"%hostid%"
]

[Registry_SaveRebootCounter]
openKey [HKLM\SOFTWARE\opsi.org\winst]
set "RebootFlag" = "$act_reboot_counter$"
Entscheidend sind eigentlich nur folgende Zeilen:

Code: Alles auswählen

; Prüfe opsi Aufruf
set $win_runmode$ = function-opsi-start_check("test")
if ($only_shutdown$ = "true")
   if ($win_runmode$ = "shutdown")
      Message "Starte Windows Updates ..."
      set $exitcode$ = shellCall('"%ScriptPath%\..\wsusoffline_depot\client\cmd\DoUpdate.cmd" /updatecpp /updatetsc /instdotnet35 /instdotnet4 /instpsh /instwmf')
   else
      Message "Windows Updates beim Start/Betrieb nicht erlaubt"
   endif
   isSuccess
endif
Die Variable $only_shutdown$ steht bei allen Rechnern auf "true", bei denen die Funktion "Install By Shutdown" aktiviert ist. Danach wird überprüft, ob sich Windows im Herunterfahren/Neustarten befindet (Variable $win_runmode$). Dann wird das wsusoffline cmd aufgerufen. In diesem cmd ist kein Reboot enthalten bzw. der entsprechende Parameter fehlt.
Und der Fehler tritt auch auf, wenn ich die Maschine erstmalig hochfahre und das Paket vorher noch nie gelaufen ist. Paket steht auf Always.

Der Vollständigkeitshalber hier noch die ausgelagerten Funktionen, welche teilweise in o.g. Beispiel aufgerufen werden:

Code: Alles auswählen

DefFunc function-unzip($ZipFile$ : string, $ZipTarget$ : string) : string
   set $result$ = "0"

   Message "Entpacke Dateien ..."

   ; --- Workflow ---
   execWith_ps_unzip "powershell" winst /64Bit
   set $result$ = getLastExitcode

   if ($result$ = "0")
      Message "Dateien erfolgreich entpackt"
   else
      logError "Fehler beim Entpacken der Datei '"+$ZipFile$+"' nach '"+$ZipTarget$+"' - Fehlercode: "+$result$
      isFatalError "Exit Code: "+$result$
   endif

   ; --- Sections ---
   [execWith_ps_unzip]
   $command={ expand-archive -path "$ZipFile$" -destinationpath "$ZipTarget$" -force }
   try { $msg=invoke-command -ScriptBlock $command -erroraction stop -errorvariable act_errormsg ; $act_errorstatus=$? ; $act_exitcode=$Lastexitcode }
   catch { if ((!$act_exitcode) -or ($act_exitcode -eq 0)) { $act_exitcode=8 } }
   finally { }

   if ($act_errorstatus)
   {
      $act_exitcode=0
      write-host "Dateien erfolgreich entpackt"
   }
   else
   {
      if ((!$act_exitcode) -or ($act_exitcode -eq 0)) { $act_exitcode=8 }
      write-host "Fehler beim Entpacken der Datei '$ZipFile$' nach '$ZipTarget$' - Fehlercode: $act_exitcode"
   }
   if ($act_exitcode -eq 0) { Exit 0 } else { Exit 1 }
endfunc

DefFunc function-rebootflag_check(ref $act_reboot_counter$ : string, $max_reboot_counter$ : string) : string
   Message "Setze Rebootflag"

   ; ------------- Create Reboot flag registry key ----------------------------------------------
   if  (GetRegistryStringValue32("[HKLM\SOFTWARE\opsi.org\winst] "+"RebootFlag") = "")
	   set $act_reboot_counter$ = "0"
   else
	   Set $act_reboot_counter$ = GetRegistryStringValue32("[HKLM\SOFTWARE\opsi.org\winst] "+"RebootFlag")
   endif
   comment "Rebootflag (Aktuell: "+$act_reboot_counter$+" - Max: "+$max_reboot_counter$+")"
endfunc

DefFunc function-opsi-start_check($arg1$ : string) : string
   DefstringList $ServiceCallList$
   DefVar $win_runmode$
   set $result$ = "boot"

   Message "Pruefe opsi Aufruf (boot/shutdown)"

   set $ServiceCallList$ = getReturnListFromSection("opsiservicecall_Shutdown_Detection /opsiclientd")
   set $win_runmode$ = takeString(0, $ServiceCallList$)

   if ($win_runmode$ = "true")
      set $result$ = "shutdown"
      Message "opsi Aufruf beim Windows Shutdown"
   else
      set $result$ = "boot"
      Message "opsi Aufruf beim Windows Boot"
   endif

   [opsiservicecall_Shutdown_Detection]
   "method":"isEventRunning"
   "params":[
            'on_shutdown',
            ]
endfunc

DefFunc function-reboot_check(ref $act_reboot_counter$ : string, $RebootMode$ : string) : string
   set $result$ = "0"

   Message "Teste ob Reboot notwendig ..."

   ; --- Workflow ---
   execWith_ps_reboot_check "powershell" WINST /64Bit
   set $result$ = getLastExitCode

   if $result$ = "1"
      Message "Reboot notwendig ..."
      set $act_reboot_counter$ = calculate($act_reboot_counter$+"+1")
      Registry_SaveRebootCounter

      if ($RebootMode$ = "ImmediateReboot")
         ExitWindows /ImmediateReboot
      else
         ExitWindows /Reboot
      endif
   else
      Message "Kein Reboot notwendig"
   endif

   ; --- Sections ---
   [execWith_ps_reboot_check]
   if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction SilentlyContinue) { exit 1 }
   if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue) { exit 1 }
   if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue) { exit 1 }
   try { 
     $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
     $status = $util.DetermineIfRebootPending()
     if(($status -ne $null) -and $status.RebootPending){
       exit 1
     }
   }catch{}
   exit 0

   [Registry_SaveRebootCounter]
   openKey [HKLM\SOFTWARE\opsi.org\winst]
   set "RebootFlag" = "$act_reboot_counter$"
endfunc

DefFunc function-exitcode_check($exitcode$ : string, ref $act_reboot_counter$ : string, $max_reboot_counter$ : string, $Reboot$ : string, $RebootMode$ : string) : string
   Message "Teste Erfolg der Installation via exitcode "+$exitcode$

   ; --- Workflow ---
   ; informations to exit codes see
   ; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
   ; http://msdn.microsoft.com/en-us/library/aa368542.aspx
   Switch $exitcode$
           Case "0"
                   comment "Looks good: setup program gives exitcode zero"
           EndCase
           Case "2"
                   logError "Fatal: The system cannot find the file specified: " + $exitcode$
                   isFatalError "Exit Code: "+ $exitcode$
           EndCase
           Case "3"
                   logError "Fatal: The system cannot find the path specified: " + $exitcode$
                   isFatalError "Exit Code: "+ $exitcode$
           EndCase
           Case "1605"
                   comment "ERROR_UNKNOWN_PRODUCT  1605"
                   comment "This action is only valid for products that are currently installed."
                   comment "Uninstall of a not installed product failed - no problem"
           EndCase
           Case "1641"
                   comment "looks good: setup program gives exitcode 1641"
                   comment "ERROR_SUCCESS_REBOOT_INITIATED 1641"
                   comment "The installer has initiated a restart."
                   comment "This message is indicative of a success."
                   if ($Reboot$ = "true")
                      set $act_reboot_counter$ = calculate($act_reboot_counter$+"+1")
                      Registry_SaveRebootCounter
                      if ($RebootMode$ = "ImmediateReboot")
                         ExitWindows /ImmediateReboot
                      else
                         ExitWindows /Reboot
                      endif
                   endif
           EndCase
           Case "3010"
                   comment "looks good: setup program gives exitcode 3010"
                   comment "ERROR_SUCCESS_REBOOT_REQUIRED 3010"
                   comment "A restart is required to complete the install."
                   comment "This message is indicative of a success."
                   if ($Reboot$ = "true")
                      set $act_reboot_counter$ = calculate($act_reboot_counter$+"+1")
                      Registry_SaveRebootCounter
                      if ($RebootMode$ = "ImmediateReboot")
                         ExitWindows /ImmediateReboot
                      else
                         ExitWindows /Reboot
                      endif
                   endif
           EndCase
           Case "3011"
                   comment "looks good: setup program gives exitcode 3011"
                   comment "ERROR_SUCCESS_REBOOT_REQUIRED 3011"
                   comment "A restart is required to complete the install."
                   comment "This message is indicative of a success."
                   if ($Reboot$ = "true")
                      set $act_reboot_counter$ = calculate($act_reboot_counter$+"+1")
                      Registry_SaveRebootCounter
                      if ($RebootMode$ = "ImmediateReboot")
                         ExitWindows /ImmediateReboot
                      else
                         ExitWindows /Reboot
                      endif
                   endif
           EndCase
           Case "5100"
                   logError "Fatal: The user's computer does not meet system requirements: " + $exitcode$
                   isFatalError "Exit Code: "+ $exitcode$
           EndCase
           Case "14098"
                   logError "Fatal: The Component Store has been corrupted: " + $exitcode$
                   isFatalError "Exit Code: "+ $exitcode$
           EndCase
           Case "2359302"
                   comment "SUS_S_ALREADY_INSTALLED  240006"
                   comment "The update to be installed is already installed - no problem"
           EndCase
           DefaultCase
                   logError "Fatal: Setup gibt einen unbekannten exitcode ungleich 0: " + $exitcode$
                   isFatalError "Exit Code: "+ $exitcode$
           EndCase
   EndSwitch

   [Registry_SaveRebootCounter]
   openKey [HKLM\SOFTWARE\opsi.org\winst]
   set "RebootFlag" = "$act_reboot_counter$"
endfunc

DefFunc function-version_check($CheckFile$ : string, $CheckDepotVersion$ : string, $CheckMethod$ : string, $CheckBitRate$ : string) : string
   set $result$ = "false"

   Message "Pruefe installierte Version ..."

   if (strPart($CheckMethod$,"1","4") = "file")
      sub "function-global-version_file_check.opsiscript"
   endif

   if (strPart($CheckMethod$,"1","8") = "registry")
      sub "function-global-version_registry_check.opsiscript"
   endif

   if (strPart($CheckMethod$,"1","8") = "software")
      sub "function-global-version_software_check.opsiscript"
   endif
endfunc

DefFunc function-create_shortcut($SourceExe$ : string, $Parameter$ : string, $DestinationPath$ : string, $WorkingDir$ : string) : string
   set $result$ = "0"

   Message "Erstelle Verknuepfung ..."

   ; --- Workflow ---
   execWith_ps_create_shortcut "powershell" winst /64Bit
   set $result$ = getLastExitcode
   
   if ($result$ = "0")
      Message "Verknuepfung erfolgreich erstellt"
   else
      logError "Fehler beim Erstellen der Verknüpfung - Fehlercode: "+$result$
      isFatalError "Exit Code: "+$result$
   endif

   ; --- Sections ---
   [execWith_ps_create_shortcut]
   if ("$WorkingDir$" -eq "") { $act_wd="$(split-path -path $SourceExe$)" } else { $act_wd="$WorkingDir$" }
   $WshShell = New-Object -comObject WScript.Shell
   $Shortcut = $WshShell.CreateShortcut("$DestinationPath$")
   $Shortcut.TargetPath = "$SourceExe$"
   $Shortcut.Arguments = "$Parameter$"
   $Shortcut.WorkingDirectory = "$act_wd"
   $Shortcut.Save()
   if ($?) {Exit(0)} else {Exit(1)}
endfunc
Antworten