How to make a script re-run?

Antworten
lloydsystems
Beiträge: 22
Registriert: 03 Feb 2013, 09:46

How to make a script re-run?

Beitrag von lloydsystems »

Hi,

I have written an opsi script to apply Windows updates that are downloaded and installed using wsusoffline update. There is only 1 script - setup.ins - that reads install options from product properties, then launches the wsusoffline DoUpdate.cmd script.

The exit codes can be read and checked. 1641 and 3010 request a reboot, for which I issue 'ExitWindows /Reboot', and 3011 means it wants a reboot and to run again. For this I tried 'ExitWindows /ImmediateReboot' with the theory that the script status will not update and therefore cause it to run again. But, in practice, this is no good.

Windows 7 waits until the PC is shutting down to finish the install of the patches. With the ImmediateReboot it kills Windows and does not allow this to complete. As a result, the patches are not applied, and the temporary install folders are left orphaned on the C: drive.

So, I have 2 questions.
1. How can opsi handle the shutdown to play nice with Windows 7 updates?
2. How can I make the setup script run again (by itself) to finish the job?

Regards,

Stephen Jones
bmsoft
Beiträge: 43
Registriert: 02 Feb 2012, 12:30

Re: How to make a script re-run?

Beitrag von bmsoft »

lloydsystems hat geschrieben: 1. How can opsi handle the shutdown to play nice with Windows 7 updates?
ExitWindows /ImmediateReboot is the right way, but you must take care of finding the entry point by yourself. Check the manual, it shows an example:
http://download.uib.de/opsi_stable/doc/ ... nds-reboot
2. How can I make the setup script run again (by itself) to finish the job?
We use offline updates + wsus in one package ... see the snippet below.

Code: Alles auswählen

(...)
set $WinstRegKey$ = "HKLM\SOFTWARE\opsi.org\winst"
set $Flag$ = GetRegistryStringValue32 ("[" + $WinstRegKey$ + "] " + "WUStatus")
if ($Flag$ = "")
    set $Flag$ = "0"
endif

set $FlagValue$ = "3000"

if ($Flag$ INT<= $FlagValue$)
    sub_DoUpdate
    if ($ExitCode$ = "3010")
        set $Flag$ = "3010"
        Registry_SaveWUStatus
        Sub_Reboot
    else
(...)
You can build the logic you need (e.g. offline + wsus, offline only, wsus only) and after rebooting the script continuese at the last stage.

HTH, Lorenzo
Antworten