Comment: Creating IIS Websites and Virtual Folders Example
Comment: ========================================
Comment: This project illustrates enumerating and creating IIS websites and virtual folders
Comment: Using conditional execution, the custom wizard screen is shown and the IIS metabase is updated only when the main setup feature is selected for installation
 
Comment: This project uses:
Comment: ------------------
Comment: 1. The Get IIS Site List command to obtain a list of available websites
Comment: 2. The Set Variable command with the Persistent option to automatically remember the chosen website and virtual folder names when restarting setup
Comment: 3. The Get Component State command to create/remove the website and show the custom wizard dialog only if necessary
Comment: 4. The #PROJDIR# pre-defined compiler variable to read sample website files from the project folder
Comment: 5. A customized Wizard dialog with the controls and logic for displaying existing websites and capturing new website/virtual folder information
Comment: 6. The MessageBox command to confirm deleting websites/virtual folders upon uninstall
Comment: 7. The Terminate Install command to cancel setup if so desired
Comment: 8. The Get IIS Site Index, Create Virtual Folder, Create IIS Site, Delete IIS Site, and Delete Virtual Folder commands for querying and updating the IIS metabase
Comment: 9. The Get System Settings command to determine if IIS is available on the target system before starting setup
 
Comment: See in-code comments for more information.
 
[DEFINE REGION: Check Application Requirements]
Comment: Quit, unless we have IIS available
Get System Setting Internet Information Server 6 into CHECKSYSTEM
if Variable CHECKSYSTEM not Equals TRUE
  MessageBox: $TITLE$ Setup Error, This product requires at least Internet Information Server 6.$NEWLINE$$NEWLINE$Setup cannot continue.
  Terminate Installation
end
[END REGION]
 
[DEFINE REGION: Check/Install Application Pre-Requisites]
 
[DEFINE REGION: Check Application Pre-Requisites]
Comment: Check setup pre-requisites
Set Variable PREREQ to FALSE
Set Variable PRELIST to 
[compiler if Variable BUILDMODE not Equals PATCH]
if Variable NEEDSUPGRADE Equals TRUE
  Set Variable PREREQ to TRUE
  Set Variable PRELIST to $PRELIST$$NEWLINE$Previous Version Uninstallation
end
[compiler end]
[END REGION]
 
[DEFINE REGION: Install Application Pre-Requisites]
Comment: Install setup pre-requisites
if Variable PREREQ not Equals FALSE
  Display Dialog: prereq, wait for dialog to return (modal)
  if Variable WIZARD Equals CANCEL
    Terminate Installation
  end
  Display Dialog: progressprereq, use as progress dialog (non-modal)
  [compiler if Variable BUILDMODE not Equals PATCH]
  if Variable NEEDSUPGRADE Equals TRUE
    Set Variable REMOVEOLD to 
    Set Variable ERROROLD to 
    Install/Remove MSI Package $PRODUCTCODE$[REMOVE=ALL] (get result into variable REMOVEOLD)
    if Variable REMOVEOLD Equals ERROR
      MessageBox: $TITLE$ Setup, Unable to uninstall old version of $TITLE$. Please uninstall it yourself using Control Panel Add-Remove Programs before attempting to install this product.$NEWLINE$$NEWLINE$$ERROROLD$
      Terminate Installation
    end
    if Variable REMOVEOLD Equals REBOOT
      MessageBox: $TITLE$ Setup, Your computer needs to be restarted before $TITLE$ Setup can continue.$NEWLINE$$NEWLINE$Please save your work in all running programs and click OK to restart your computer. Setup will resume once your computer restarts.$NEWLINE$$NEWLINE$If you click CANCEL, setup will exit. You will have to run setup again at a later time to install $TITLE$.
      if Variable REBOOTNOW Equals OK
        Reboot Computer and Resume Setup
      else
        Terminate Installation
      end
    end
    Set Variable MAINTENANCE to FALSE
  end
  [compiler end]
  Hide Dialog
end
[END REGION]
 
[END REGION]
 
[DEFINE REGION: Define Setup Globals]
Comment: Define Setup Components
Define Component: Creating IIS Websites and Virtual Folders
 
Comment: Initialize Setup Globals
Get System Setting Windows NT Kernel (NT4, 2000, XP, 2003, Vista, 2008, 7, 2008 R2, 8, 2012) into ISNT
Get Folder Location System->Program Files Directory into PROGRAMFILES
Get Common Folder Location System->Program Files Directory into COMMONFILES
Get Common Folder Location Start Menu->Programs Group into SHORTCUTFILESALL
Get Folder Location Start Menu->Programs Group into SHORTCUTFILES
if Variable SHORTCUTFILESALL Equals 
  Set Variable SHORTCUTFILESALL to $SHORTCUTFILES$
end
Get Folder Location System->Desktop Directory into DESKTOPDIR
Get Folder Location System->Windows Directory into WINDIR
Get Folder Location System->System Directory into WINSYSDIR
Get Folder Location Taskbar->Quick Launch Directory into QUICKLAUNCHDIR
Get Folder Location WWW->WWWRoot into WWWROOTDIR
[END REGION]
 
[DEFINE REGION: Setup User Interview]
if Variable MAINTENANCE Equals TRUE
  GoTo Label: Maintenance
else
  [compiler if Variable BUILDMODE not Equals PATCH]
  Comment: First Time Install
  Set Variable TARGETDIR to $PROGRAMFILES$\$TITLE$
  Set Variable STARTMENU to $TITLE$
  Comment: On first-time run, define these variables as persistent - so setup remembers their values upon restart for maintenance or repair operations
  Set Persistent Variable WEBSITE to 
  Set Persistent Variable WS2 to 
  Set Persistent Variable FOLDER to 
  Comment: Obtain the list of IIS websites into this variable here; this variable is later used by the wizard dialog to pre-populate the list of available IIS websites
  Get IIS Site List into variable SITELIST
  [compiler end]
end
 
label: Welcome Dialog
Display Dialog: welcome, wait for dialog to return (modal)
if Variable WIZARD Equals CANCEL
  GoTo Label: Main Install
end
[compiler if Variable BUILDMODE not Equals PATCH]
label: License Check
Display Dialog: licensecheck, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: Welcome Dialog
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: ReadMe Information
Display Dialog: readme, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: License Check
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: User Registration
Display Dialog: registration, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: ReadMe Information
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: Setup Type
Display Dialog: setuptype, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: User Registration
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
Comment: TO-DO: Customize your minimum setup here
if Variable MINIMUM Equals TRUE
  Deselect Component: Creating IIS Websites and Virtual Folders
else
  if Variable COMPLETE Equals TRUE
    Select Component: Creating IIS Websites and Virtual Folders
  end
end
label: Custom Setup
Display Dialog: componentstree (if variable PERSONALIZED is TRUE), wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: Setup Type
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: Destination Directory
Display Dialog: destination, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: Custom Setup
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: IIS Config
Get Component Creating IIS Websites and Virtual Folders Selection State into Variable DIALOGTEST
if Variable DIALOGTEST Equals TRUE
  Comment: Display this dialog only if the main setup feature has been selected for installation
  Display Dialog: wizard, wait for dialog to return (modal)
end
if Variable WIZARD Equals BACK
  GoTo Label: Destination Directory
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
label: Start Menu
Display Dialog: startmenu, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  GoTo Label: IIS Config
else
  if Variable WIZARD Equals CANCEL
    GoTo Label: Main Install
  end
end
[compiler end]
label: Start Installation
Display Dialog: startinstallation, wait for dialog to return (modal)
if Variable WIZARD Equals BACK
  [compiler if Variable BUILDMODE not Equals PATCH]
  GoTo Label: Start Menu
  [compiler else]
  GoTo Label: Welcome Dialog
  [compiler end]
else
  GoTo Label: Main Install
end
 
label: Maintenance
Comment: Maintenance Install/Uninstall
wizard loop
Display Dialog: maintenance, wait for dialog to return (modal)
Display Dialog: componentstree (if variable MODIFY is TRUE), wait for dialog to return (modal)
Display Dialog: startinstallation, wait for dialog to return (modal)
end
[END REGION]
 
[DEFINE REGION: Process (Un)Installation]
label: Main Install
Comment: Exit Setup if Wizard Loop cancelled
if Variable WIZARD Equals CANCEL
  Terminate Installation
end
 
Comment: Prepare to install
Set Variable PROGRESSTEXT to Installing $TITLE$
Set Variable SUCCESS to 
Set Variable LASTERROR to 
if Variable ALLUSERS Equals TRUE
  Set Variable SHORTCUTFOLDER to $SHORTCUTFILESALL$\$STARTMENU$
else
  Set Variable SHORTCUTFOLDER to $SHORTCUTFILES$\$STARTMENU$
end
Display Dialog: progress, use as progress dialog (non-modal)
 
Comment: Modify Target System
[DEFINE REGION: Perform Uninstallation]
if Variable REMOVE Equals TRUE
  Comment: Uninstall product
  Comment: TO-DO: Insert any additional uninstall commands here
  Get Component Creating IIS Websites and Virtual Folders Selection State into Variable SELECTED
  if Variable SELECTED Equals TRUE
    Comment: Verify removal of the IIS website and virtual folder
    MessageBox: $TITLE$ Setup, Would you like to remove the website and virtual folder that setup created during installation?
    if Variable REMOVAL Equals CANCEL
      Comment: User abort - quit setup
      Terminate Installation
    end
    if Variable REMOVAL Equals YES
      Comment: Removal confirmed - delete the site and folder
      Get IIS Index for Site "$WEBSITE$" into WEBSITEINDEXVAR
      Delete Virtual Folder "$FOLDER$" in IIS Site #$WEBSITEINDEXVAR$
      Get IIS Index for Site "$WEBSITE$" into WEBSITEINDEXVAR
      Delete IIS Site #$WEBSITEINDEXVAR$
    end
  end
  Apply Uninstall (get result into variable SUCCESS)
  Set Variable PROGRESS to 100
else
  [END REGION]
  [DEFINE REGION: Perform First Time or Maintenance Installation]
  Comment: Install/Re-Install product
  Create Shortcut $SHORTCUTFOLDER$\Uninstall Creating IIS Websites and Virtual Folders to $UNINSTALLLINK$
  [OFFLINE CONTENT]
  [DEFINE WEB MEDIA Creating IIS Websites and Virtual Folders]
  Get Component Creating IIS Websites and Virtual Folders Selection State into Variable SELECTED
  if Variable SELECTED Equals TRUE
    Comment: Install the site files only if the main setup feature has been selected for installation
    Install Files #PROJDIR#\iisstart.htm to $TARGETDIR$
    Install Files #PROJDIR#\pagerror.gif to $TARGETDIR$
  end
  Comment: TO-DO: Insert any additional install commands here
  [compiler if Variable BUILDMODE Equals PATCH]
  Apply Patch (get result into variable SUCCESS)
  [compiler else]
  if Variable ADVERTISE Equals TRUE
    Apply Advertised (get result into variable SUCCESS)
  else
    Apply Install (get result into variable SUCCESS)
    if Variable SUCCESS not Equals ERROR
      if Variable SUCCESS not Equals CANCEL
        Get Component Creating IIS Websites and Virtual Folders Selection State into Variable SELECTED
        Comment: Update the IIS metabase only if the main setup feature has been selected
        if Variable SELECTED Equals TRUE
          Get IIS Index for Site "$WEBSITE$" into WEBSITEINDEXVAR
          Get IIS Index for Site "$WS2$" into WIX
          if Variable WEBSITEINDEXVAR Equals 0
            Comment: Create the new website only if it doesn't already exist
            Create IIS Site "$WEBSITE$"
            Get IIS Index for Site "$WEBSITE$" into WEBSITEINDEXVAR
          end
          Comment: Create the virtual folder
          Create Virtual Folder "$FOLDER$" in IIS Site #$WEBSITEINDEXVAR$, pointing to physical location $TARGETDIR$
          Comment: Obtain the IIS anonymous account user name
          Get System Setting IIS Anonymous User Account into INETUSR
          Comment: Set read permissions on the physical target folder of the new virtual folder
          Set Read Permissions on File System Object "$TARGETDIR$" for $INETUSR$
        end
      end
    end
  end
  [compiler end]
  Set Variable PROGRESS to 100
end
[END REGION]
[END REGION]
 
[DEFINE REGION: Finish Setup]
Comment: End of Installation
Hide Dialog
Display Dialog: finish, wait for dialog to return (modal)
if Variable SILENT Equals FALSE
  if Variable REBOOTCOMPUTER Equals TRUE
    if Variable SUCCESS Equals REBOOT
      Reboot Computer
    end
  end
  if Variable RUNAPP Equals TRUE
    if Variable REMOVE Equals FALSE
      if Variable SUCCESS Equals COMPLETE
        Comment: Start the IIS Manager to verify configuration
        Run Program inetmgr 
      end
    end
  end
end
[END REGION]
 
