Comment: Script to Schedule, Download, and Install Updates
 
[compiler if Variable UPDATE_SCHEDULING Equals TRUE]
Comment: IMPORTANT!
Comment: If your setup uses the Native Engine,
Comment: And the Scheduled Web Update Mode;
Comment: Comment-in (enable) the line below:
Comment: Set Variable NATIVE_ENGINE to TRUE
 
Set Variable UPDATE_SCHEDULING to TRUE
 
[DEFINE REGION: Update Mode?]
Set Variable COMMANDLINE to $CMDLINE$
if Variable COMMANDLINE not Contains /update
  Set Variable UPDATE_SCHEDULE to FALSE
  if Variable MAINTENANCE Equals FALSE
    Set Variable UPDATE_SCHEDULE to TRUE
  end
  if Variable UPDATE_SCHEDULE Equals TRUE
    Set Persistent Variable UPDATE_DOWNLOAD to TRUE
    Set Persistent Variable UPDATE_INSTALL to FALSE
    Set Persistent Variable UPDATE_AUTO to FALSE
    Set Persistent Variable UPDATE_LOG to TRUE
    Set Persistent Variable UPDATE_NTKERNEL to 
    Set Persistent Variable WINDOWSINSTALLERDIR to 
    Get Common Folder Location System->Windows Directory into WINDOWSINSTALLERDIR
    Get System Setting Windows NT Kernel (NT4, 2000, XP, 2003, Vista, 2008, 7, 2008 R2, 8, 2012) into UPDATE_NTKERNEL
    Set Variable WINDOWSINSTALLERDIR to $WINDOWSINSTALLERDIR$\Installer
    Set Variable ALLUSERS_BACKUP to $ALLUSERS$
    Set Variable ALLUSERS to TRUE
    Set Persistent Variable UPDATEEXE_ALLUSERS to $UNINSTALLLINK$
    Set Variable ALLUSERS to FALSE
    Set Persistent Variable UPDATEEXE_JUSTME to $UNINSTALLLINK$
    Set Variable ALLUSERS to $ALLUSERS_BACKUP$
  end
  if Variable MAINTENANCE Equals FALSE
    if Variable NEEDSUPGRADE Equals FALSE
      Write Registry Key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\$TITLE$ Update Setup, $UPDATEEXE_JUSTME$ /updatesetup
    end
  end
  if Variable UPDATE_NTKERNEL Equals TRUE
    Create Shortcut $WINDOWSINSTALLERDIR$\#TITLE# Updates to $UPDATEEXE_JUSTME$
  else
    Recursively Delete Files $WINDOWSINSTALLERDIR$\$TITLE$ Updates.bat
    Write into Text File $WINDOWSINSTALLERDIR$\$TITLE$ Updates.bat from Value @echo off (at end of file)
    Write into Text File $WINDOWSINSTALLERDIR$\$TITLE$ Updates.bat from Value "$UPDATEEXE_JUSTME$" /update (at end of file)
  end
  if Variable UPDATEEXE_ALLUSERS not Equals (Ignore Case) $UPDATEEXE_JUSTME$
    if Variable MAINTENANCE Equals FALSE
      if Variable NEEDSUPGRADE Equals FALSE
        Write Registry Key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\$TITLE$ Update Setup for All Users, $UPDATEEXE_ALLUSERS$ /updatesetup
      end
    end
    if Variable UPDATE_NTKERNEL Equals TRUE
      Create Shortcut $WINDOWSINSTALLERDIR$\#TITLE# Updates for All Users to $UPDATEEXE_ALLUSERS$
    else
      Recursively Delete Files $WINDOWSINSTALLERDIR$\$TITLE$ Updates for All Users.bat
      Write into Text File $WINDOWSINSTALLERDIR$\$TITLE$ Updates for All Users.bat from Value @echo off (at end of file)
      Write into Text File $WINDOWSINSTALLERDIR$\$TITLE$ Updates for All Users.bat from Value "$UPDATEEXE_ALLUSERS$" /update (at end of file)
    end
  end
  Set Variable ALLUSERS_BACKUP to $ALLUSERS$
  Set Variable ALLUSERS to TRUE
  Delete Files $ENGINECACHE$\installedupdates.dat (when uninstalling)
  Set Variable ALLUSERS to FALSE
  Delete Files $ENGINECACHE$\installedupdates.dat (when uninstalling)
  Set Variable ALLUSERS to $ALLUSERS_BACKUP$
  Delete Files $WINDOWSINSTALLERDIR$\#TITLE# Updates.bat (when uninstalling)
  Delete Files $WINDOWSINSTALLERDIR$\#TITLE# Updates for All Users.bat (when uninstalling)
  GoTo Label: End of Updates
end
[END REGION]
 
[DEFINE REGION: Schedule Updates]
if Variable COMMANDLINE not Contains /updatesetup
  GoTo Label: Check for Updates
end
 
Get System Setting Windows 9X Kernel (95, 98, ME) into WIN9X
Set Variable UPDATE_DATE to Every day
Set Variable UPDATE_TIME to 3:00 AM
Set Variable UPDATE_KEEP to TRUE
if Variable WIN9X not Equals TRUE
  Get System Setting Logged on Domain Name into UPDATE_DOMAIN
  if Variable UPDATE_DOMAIN Equals 
    Get System Setting Logged on Computer Name into UPDATE_DOMAIN
  end
  Get System Setting Logged on User Name into UPDATE_USER
  Set Persistent Variable UPDATE_USER to $UPDATE_DOMAIN$\$UPDATE_USER$
  Set Variable UPDATE_PASS to 
end
 
Show icon in system tray, minimize setup to system tray
MessageBalloon: $TITLE$ Updates, Configure automatic updates for $TITLE$.
 
label: Update Setup Welcome
Display Dialog: update_setup_welcome, wait for dialog to return (modal)
if Variable WIZARD Equals CANCEL
  GoTo Label: Update Setup End of Dialogs
end
label: Update Setup Schedule
Display Dialog: update_setup_schedule, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: Update Setup Welcome
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Update Setup End of Dialogs
  end
end
label: Update Setup Account
if Variable WIN9X Equals FALSE
  if Variable UPDATE_KEEP Equals TRUE
    Display Dialog: update_setup_account, wait for dialog to return (modal)
  end
end
if Variable WIZARD Equals BACK
  GoTo Label: Update Setup Schedule
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Update Setup End of Dialogs
  end
end
label: Update Setup Finished
Display Dialog: update_setup_finish, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: Update Setup Account
end
label: Update Setup End of Dialogs
 
if Variable WIZARD Equals CANCEL
  Terminate Installation
else
  Get Common Folder Location System->Windows Directory into WINDOWSINSTALLERDIR
  Set Variable WINDOWSINSTALLERDIR to $WINDOWSINSTALLERDIR$\Installer
  if Variable UPDATE_KEEP Equals TRUE
    Get System Setting Windows NT Kernel (NT4, 2000, XP, 2003, Vista, 2008, 7, 2008 R2, 8, 2012) into UPDATE_NTKERNEL
    if Variable UPDATE_NTKERNEL Equals TRUE
      Get System Setting Windows Vista into UPDATE_VISTA
      if Variable ALLUSERS Equals TRUE
        if Variable UPDATE_VISTA Equals FALSE
          Schedule Task $TITLE$ Updates to run weekly
        else
          Schedule Task $TITLE$ Updates to run weekly
        end
      else
        if Variable UPDATE_VISTA Equals FALSE
          Schedule Task $TITLE$ Updates to run weekly
        else
          Schedule Task $TITLE$ Updates to run weekly
        end
      end
    else
      if Variable ALLUSERS Equals TRUE
        Schedule Task $TITLE$ Updates to run weekly
      else
        Schedule Task $TITLE$ Updates to run weekly
      end
    end
  else
    Delete Scheduled Task $TITLE$ Updates
  end
  Delete Registry VALUE HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\$TITLE$ Update Setup
  Delete Registry VALUE HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\$TITLE$ Update Setup for All Users
end
 
Terminate Installation
[END REGION]
 
[compiler else]
Set Variable UPDATE_SCHEDULING to FALSE
 
[compiler if Variable UPDATE_SCHEDULING Equals THIRD]
if Variable MAINTENANCE Equals TRUE
  [compiler end]
  if Variable CMDLINE not Contains /update
    GoTo Label: End of Updates
  end
  [compiler if Variable UPDATE_SCHEDULING Equals THIRD]
end
[compiler end]
 
[compiler if Variable UPDATE_SCHEDULING not Equals THIRD]
Set Variable UPDATE_DOWNLOAD to TRUE
Set Variable UPDATE_AUTO to FALSE
Set Variable UPDATE_LOG to TRUE
[compiler else]
if Variable MAINTENANCE Equals TRUE
  Set Variable UPDATE_DOWNLOAD to TRUE
  Set Variable UPDATE_AUTO to FALSE
  Set Variable UPDATE_LOG to TRUE
else
  Set Variable UPDATE_DOWNLOAD to FALSE
  Set Variable UPDATE_AUTO to TRUE
  Set Variable UPDATE_LOG to FALSE
end
[compiler end]
 
[compiler end]
 
[DEFINE REGION: Download and Install Updates]
label: Check for Updates
Set Variable UPDATE_GET_INI to 
Download File #UPDATE_SERVER# into $SUPPORTDIR$\updates.ini (get result into variable UPDATE_GET_INI)
 
Comment: Check Internet connectivity
if Variable UPDATE_GET_INI not Equals SUCCESS
  [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
  [compiler else]
  [compiler if Variable UPDATE_SCHEDULING not Equals THIRD]
  MessageBox: $TITLE$ Update, Unable to contact update server for $TITLE$.$NEWLINE$$NEWLINE$Please check your Internet connection and try again.
  [compiler else]
  if Variable MAINTENANCE Equals TRUE
    MessageBox: $TITLE$ Update, Unable to contact update server for $TITLE$.$NEWLINE$$NEWLINE$Please check your Internet connection and try again.
    Terminate Installation
  end
  GoTo Label: End of Updates
  [compiler end]
  [compiler end]
  Terminate Installation
end
Comment: Check update availability
Get INI $SUPPORTDIR$\updates.ini, [Update Packs for Versions] $VERSION$ Value into Variable UPDATE_AVAILABLE
if Variable UPDATE_AVAILABLE Equals 
  [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
  [compiler else]
  [compiler if Variable UPDATE_SCHEDULING not Equals THIRD]
  Comment: (DanielTan) MessageBox: $TITLE$ Update, No updates are available for $TITLE$ at this time.$NEWLINE$$NEWLINE$Please check back again later.$NEWLINE$$NEWLINE$
  [compiler else]
  if Variable MAINTENANCE Equals TRUE
    MessageBox: $TITLE$ Update, No updates are available for $TITLE$ at this time.$NEWLINE$$NEWLINE$Please check back again later.$NEWLINE$$NEWLINE$kns
    Terminate Installation
  end
  GoTo Label: End of Updates
  [compiler end]
  [compiler end]
  Terminate Installation
end
 
if Variable UPDATE_LOG Equals TRUE
  Comment: Remove previously installed updates from list of available updates
  label: Remove Previously Installed
  Set Variable UPDATE_PREVIOUSLY_INSTALLED to 
  Read from Text File $EXEDIR$\installedupdates.dat into Variable UPDATE_PREVIOUSLY_INSTALLED (get EOF into UPDATE_EOF)
  if Variable UPDATE_PREVIOUSLY_INSTALLED not Equals 
    Replace $UPDATE_PREVIOUSLY_INSTALLED$$NEWLINE$ with  in variable UPDATE_AVAILABLE
    Replace $NEWLINE$$UPDATE_PREVIOUSLY_INSTALLED$ with  in variable UPDATE_AVAILABLE
    Replace $UPDATE_PREVIOUSLY_INSTALLED$ with  in variable UPDATE_AVAILABLE
  end
  if Variable UPDATE_EOF Equals FALSE
    GoTo Label: Remove Previously Installed
  end
  Comment: Quit if no new updates are available
  if Variable UPDATE_AVAILABLE Equals 
    [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
    [compiler else]
    MessageBox: $TITLE$ Update, No updates are available for $TITLE$ at this time.$NEWLINE$$NEWLINE$Please check back again later.
    [compiler end]
    Terminate Installation
  end
end
 
Comment: Gather update details
Set Variable UPDATE_REBOOT to FALSE
Set Variable UPDATE_DETAIL to 
Set Variable UPDATE_AVAILABLE_TEMP to $UPDATE_AVAILABLE$
Set Variable UPDATE_COUNT to 0
label: Form Description
Parse String $UPDATE_AVAILABLE_TEMP$ into Variables UPDATE_NAME and UPDATE_AVAILABLE_TEMP (Split at first occurrence of pattern)
UPDATE_COUNT = $UPDATE_COUNT$ + 1
Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] Description Value into Variable UPDATE_DETAIL_TEMP
if Variable UPDATE_DETAIL_TEMP not Equals 
  if Variable UPDATE_COUNT Equals 1
    Set Variable UPDATE_DETAIL to $UPDATE_NAME$$NEWLINE$$UPDATE_DETAIL_TEMP$
  else
    Set Variable UPDATE_DETAIL to $UPDATE_DETAIL$$NEWLINE$$NEWLINE$$UPDATE_NAME$$NEWLINE$$UPDATE_DETAIL_TEMP$
  end
end
if Variable UPDATE_AVAILABLE_TEMP not Equals 
  GoTo Label: Form Description
end
 
Comment: Choose updates to download
if Variable UPDATE_DOWNLOAD Equals TRUE
  [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
  MessageBalloon: Updates are available for $TITLE$, The Setup Wizard has found updates for $TITLE$. Click here to download these updates.
  Show icon in system tray, minimize setup to system tray
  [compiler end]
end
label: Download Prompt
if Variable UPDATE_DOWNLOAD not Equals TRUE
  Set Variable UPDATE_SELECTED to $UPDATE_AVAILABLE$
else
  Set Variable UPDATE_SELECTED to $UPDATE_AVAILABLE$
  Display Dialog: update_notify_download, wait for dialog to return (modal)
end
if Variable WIZARD Equals BACK
  Run Program $UNINSTALLLINK$ /updatesetup
  GoTo Label: Download Prompt
end
if Variable WIZARD Equals CANCEL
  Terminate Installation
end
if Variable UPDATE_SELECTED Equals 
  MessageBox: $TITLE$ Updates, Please select some updates to download.
  GoTo Label: Download Prompt
end
 
Comment: Download selected updates
[compiler if Variable UPDATE_SCHEDULING Equals TRUE]
MessageBalloon: Downloading $TITLE$ updates..., The Setup Wizard is downloading updates.$NEWLINE$You can continue working while updates are being downloaded. To view detailed progress, click the $TITLE$ Update icon below.
Show icon in system tray, minimize setup to system tray
[compiler end]
Set Variable UPDATE_CURRENT to 0
Set Variable UPDATE_DOWNLOADED to 0
Set Variable UPDATE_SELECTED_TEMP to $UPDATE_SELECTED$
Set Variable UPDATE_DOWNLOAD_PROGRESS to 
Set Variable UPDATE_DETAIL_INSTALL to 
label: Download Updates
UPDATE_CURRENT = $UPDATE_CURRENT$ + 1
Parse String $UPDATE_SELECTED_TEMP$ into Variables UPDATE_NAME and UPDATE_SELECTED_TEMP (Split at first occurrence of pattern)
if Variable UPDATE_NAME not Equals 
  Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] Description Value into Variable UPDATE_DETAIL_INSTALL_TEMP
  if Variable UPDATE_DETAIL_INSTALL_TEMP not Equals 
    if Variable UPDATE_CURRENT Equals 1
      Set Variable UPDATE_DETAIL_INSTALL to $UPDATE_NAME$$NEWLINE$$UPDATE_DETAIL_INSTALL_TEMP$
    else
      Set Variable UPDATE_DETAIL_INSTALL to $UPDATE_DETAIL_INSTALL$$NEWLINE$$NEWLINE$$UPDATE_NAME$$NEWLINE$$UPDATE_DETAIL_INSTALL_TEMP$
    end
  end
  Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] URL Value into Variable UPDATE_DOWNLOAD_TEMP
  if Variable UPDATE_CURRENT Equals 1
    Set Variable UPDATE_DOWNLOAD_PROGRESS to Downloading $UPDATE_NAME$ for $TITLE$ ($UPDATE_CURRENT$ of $UPDATE_COUNT$)...
  else
    Set Variable UPDATE_DOWNLOAD_PROGRESS to $UPDATE_DOWNLOAD_PROGRESS$$UPDATE_DOWNLOAD_RESULT$$NEWLINE$Downloading $UPDATE_NAME$ for $TITLE$ ($UPDATE_CURRENT$ of $UPDATE_COUNT$)...
  end
  Display Dialog: update_download, use as progress dialog (non-modal)
  Set Variable UPDATE_GET_DOWNLOAD to 
   
  Download File $UPDATE_DOWNLOAD_TEMP$ into $SUPPORTDIR$\$UPDATE_NAME$.exe (get result into variable UPDATE_GET_DOWNLOAD)
  if Variable UPDATE_GET_DOWNLOAD Equals SUCCESS
    Set Variable UPDATE_DOWNLOAD_RESULT to done!
    UPDATE_DOWNLOADED = $UPDATE_DOWNLOADED$ + 1
  else
    Set Variable UPDATE_DOWNLOAD_RESULT to failed!
    Replace $UPDATE_NAME$$NEWLINE$ with  in variable UPDATE_SELECTED
    Replace $NEWLINE$$UPDATE_NAME$ with  in variable UPDATE_SELECTED
    Replace $UPDATE_NAME$ with $UPDATE_NAME$ [download was unsuccessful] in variable UPDATE_DETAIL_INSTALL
  end
  Hide Dialog
  if Variable ABORT Equals TRUE
    Terminate Installation
  end
end
if Variable UPDATE_CURRENT not Equals $UPDATE_COUNT$
  GoTo Label: Download Updates
end
 
Comment: Choose updates to install
if Variable UPDATE_AUTO Equals FALSE
  [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
  MessageBalloon: Updates are ready for $TITLE$, The Setup Wizard has downloaded updates for $TITLE$. Click here to install these updates.
  Show icon in system tray, minimize setup to system tray
  [compiler end]
end
label: Install Prompt
if Variable UPDATE_AUTO Equals TRUE
  Set Variable UPDATE_SELECTED_INSTALL to $UPDATE_SELECTED$
else
  Set Variable UPDATE_SELECTED_INSTALL to $UPDATE_SELECTED$
  Display Dialog: update_notify_install, wait for dialog to return (modal)
end
if Variable WIZARD Equals BACK
  Run Program $UNINSTALLLINK$ /updatesetup
  GoTo Label: Install Prompt
end
if Variable WIZARD Equals CANCEL
  Terminate Installation
end
if Variable UPDATE_SELECTED_INSTALL Equals 
  MessageBox: $TITLE$ Updates, Please select some updates to install.
  GoTo Label: Download Prompt
end
 
Comment: Install selected updates
[compiler if Variable UPDATE_SCHEDULING Equals TRUE]
MessageBalloon: Installing $TITLE$ updates..., The Setup Wizard is installing updates.$NEWLINE$You can continue working while updates are being installed. To view detailed progress, click the $TITLE$ Update icon below.
Show icon in system tray, minimize setup to system tray
[compiler end]
Set Variable UPDATE_CURRENT to 0
Set Variable UPDATE_SELECTED_TEMP to $UPDATE_SELECTED_INSTALL$
Set Variable UPDATE_INSTALL_PROGRESS to 
label: Install Updates
UPDATE_CURRENT = $UPDATE_CURRENT$ + 1
if Variable UPDATE_DOWNLOADED not Equals 0
  PROGRESS = $UPDATE_CURRENT$ * 100
  PROGRESS = $PROGRESS$ / $UPDATE_DOWNLOADED$
end
Parse String $UPDATE_SELECTED_TEMP$ into Variables UPDATE_NAME and UPDATE_SELECTED_TEMP (Split at first occurrence of pattern)
if Variable UPDATE_NAME not Equals 
  Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] URL Value into Variable UPDATE_DOWNLOAD_TEMP
  Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] Silent Value into Variable UPDATE_SILENT
  Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] Parameters Value into Variable UPDATE_PARAMETERS
  if Variable UPDATE_REBOOT Equals FALSE
    Get INI $SUPPORTDIR$\updates.ini, [$UPDATE_NAME$] Reboot Value into Variable UPDATE_REBOOT_TEMP
    if Variable UPDATE_REBOOT_TEMP Contains (Ignore Case) Yes
      Set Variable UPDATE_REBOOT to TRUE
    end
  end
  if Variable UPDATE_CURRENT Equals 1
    Set Variable UPDATE_INSTALL_PROGRESS to Installing $UPDATE_NAME$ for $TITLE$ ($UPDATE_CURRENT$ of $UPDATE_DOWNLOADED$)...
  else
    Set Variable UPDATE_INSTALL_PROGRESS to $UPDATE_INSTALL_PROGRESS$finished!$NEWLINE$Installing $UPDATE_NAME$ for $TITLE$ ($UPDATE_CURRENT$ of $UPDATE_DOWNLOADED$)...
  end
  Display Dialog: update_install, use as progress dialog (non-modal)
  Set Variable UPDATE_GET_DOWNLOAD to 
  if Variable UPDATE_SILENT not Contains (Ignore Case) No
    Set Variable SILENTVAR to /s
  else
    Set Variable SILENTVAR to 
  end
  Run Program $SUPPORTDIR$\$UPDATE_NAME$.exe $UPDATE_PARAMETERS$ $SILENTVAR$ REBOOTCOMPUTER=FALSE RUNAPP=FALSE REBOOTNOW=CANCEL (WAIT)
  if Variable UPDATE_LOG Equals TRUE
    Write into Text File $EXEDIR$\installedupdates.dat from Value $UPDATE_NAME$ (at end of file)
  end
  Hide Dialog
  if Variable ABORT Equals TRUE
    Terminate Installation
  end
end
if Variable UPDATE_DOWNLOADED Greater Than $UPDATE_CURRENT$
  GoTo Label: Install Updates
end
if Variable UPDATE_REBOOT Equals TRUE
  Display Dialog: update_reboot, wait for dialog to return (modal)
  [compiler if Variable UPDATE_SCHEDULING Equals TRUE]
  MessageBalloon: Restart required, Your computer needs to be restarted before changes made to $TITLE$ take effect.
  [compiler end]
  if Variable WIZARD Equals NEXT
    Reboot Computer
  end
end
 
Terminate Installation
[END REGION]
Comment: {F1074132-C22F-44F6-801A-42396816686A}
label: End of Updates
 
Comment: {F1074132-C22F-44F6-801A-42396816686A}
Comment: {F1074132-C22F-44F6-801A-42396816686A}
