Comment: Script to Schedule, Download, and Install Updates
 
[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
  else
    if Variable UPDATE_CONFIGURED Equals FALSE
      Set Variable UPDATE_SCHEDULE to TRUE
    end
  end
  if Variable UPDATE_SCHEDULE Equals TRUE
    Set Persistent Variable UPDATE_CONFIGURED to FALSE
    Set Persistent Variable UPDATE_DOWNLOAD to TRUE
    Set Persistent Variable UPDATE_INSTALL to FALSE
    Set Persistent Variable UPDATE_AUTO to FALSE
    Get Common Folder Location System->Windows Directory into WINDOWSINSTALLERDIR
    Get System Setting Windows NT Kernel (NT4, 2000, XP, 2003, Vista, 2008) into UPDATE_NTKERNEL
    Set Variable WINDOWSINSTALLERDIR to $WINDOWSINSTALLERDIR$\Installer
    Set Variable ALLUSERS_BACKUP to $ALLUSERS$
    Set Variable ALLUSERS to TRUE
    Set Variable UPDATEEXE_ALLUSERS to $UNINSTALLLINK$
    Set Variable ALLUSERS to FALSE
    Set Variable UPDATEEXE_JUSTME to $UNINSTALLLINK$
    Set Variable ALLUSERS to $ALLUSERS_BACKUP$
    if Variable NEEDSUPGRADE Equals FALSE
      Write Registry Key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\$TITLE$ Update Setup, $UPDATEEXE_JUSTME$ /updatesetup
    else
      Set Persistent Variable UPDATE_CONFIGURED to TRUE
    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 NEEDSUPGRADE Equals FALSE
        Write Registry Key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\$TITLE$ Update Setup for All Users, $UPDATEEXE_ALLUSERS$ /updatesetup
      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
  end
  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 Sunday
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 with Exit Code 1
  Comment: // User cancelled update installation
  Comment: Terminate Installation
else
  Get Common Folder Location System->Windows Directory into WINDOWSINSTALLERDIR
  Set Variable WINDOWSINSTALLERDIR to $WINDOWSINSTALLERDIR$\Installer
  Set Variable UPDATE_CONFIGURED to TRUE
  if Variable UPDATE_KEEP Equals TRUE
    Get System Setting Windows NT Kernel (NT4, 2000, XP, 2003, Vista, 2008) 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\Run\$TITLE$ Update Setup
  Delete Registry VALUE HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\$TITLE$ Update Setup for All Users
end
 
Comment: // update scheduling successfully completed
Terminate with Exit Code 0
Comment: Terminate Installation
[END REGION]
 
[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
  Comment: // update server is offline
  Terminate with Exit Code 2
  Comment: 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 
  Comment: // no updates found for product
  Terminate with Exit Code 3
  Comment: Terminate Installation
end
 
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 
  Comment: // no updates found for product
  Terminate with Exit Code 3
  Comment: Terminate Installation
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
  MessageBalloon: Updates are available for $TITLE$, The InstallAware Wizard has found updates for $TITLE$. Click here to download these updates.
  Show icon in system tray, minimize setup to system tray
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
  Comment: // User aborted
  Terminate with Exit Code 1
  Comment: 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
MessageBalloon: Downloading $TITLE$ updates..., The InstallAware 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
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
    Comment: // User aborted
    Terminate with Exit Code 1
    Comment: 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
  MessageBalloon: Updates are ready for $TITLE$, The InstallAware Wizard has downloaded updates for $TITLE$. Click here to install these updates.
  Show icon in system tray, minimize setup to system tray
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
  Comment: // User aborted
  Terminate with Exit Code 1
  Comment: 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
MessageBalloon: Installing $TITLE$ updates..., The InstallAware 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
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
PROGRESS = $UPDATE_CURRENT$ * 100
PROGRESS = $PROGRESS$ / $UPDATE_DOWNLOADED$
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
  Write into Text File $EXEDIR$\installedupdates.dat from Value $UPDATE_NAME$ (at end of file)
  Hide Dialog
  if Variable ABORT Equals TRUE
    Comment: // User aborted
    Terminate with Exit Code 1
    Comment: Terminate Installation
  end
end
if Variable UPDATE_CURRENT not Equals $UPDATE_DOWNLOADED$
  GoTo Label: Install Updates
end
if Variable UPDATE_REBOOT Equals TRUE
  MessageBalloon: Restart required, Your computer needs to be restarted before changes made to $TITLE$ take effect.
  Display Dialog: update_reboot, wait for dialog to return (modal)
  if Variable WIZARD Equals NEXT
    Comment: // Reboot required
    Terminate with Exit Code 4
    Comment: Reboot Computer
  end
end
 
Comment: // Update successfully completed
Terminate with Exit Code 0
Comment: Terminate Installation
[END REGION]
 
label: End of Updates
 
