cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
AceBear
Level 4

How to install a web application to different websites in IIS based on a condition

Hello there,

We have an IIS web application which has been released to customers and it is installed under the DefaultWebSite with file path under c:\inetpub\wwroot\.

For the next release, we would like to support two modes 1) upgrading install 2) fresh new install.

1) Upgrading install

For customers who have this application installed, it will install the new release to its current website  and to its current physical path.

2) Fresh new install

For new customers, the application should be installed under MyWebSite and new physical path such as C:\myCompany\mywebsite\myApp.

We would like the Installer dynamically check the presence of the web application on the client machine and perform Upgrading or Fresh New Install seamlessly. 

In a short summary, I need to know how to achieve the following in Installshield:

1) If a condition is true,  programmatically modify the target WebSite  to be WebSiteA, otherwise to be WebsiteB.

2) If a condition is true, programmatically  set the installation destination folder to  folderA, otherwise to folderB.

The current Installer file has Scripts and Custom Actions.  I am new to installshield. Any help is appreciated!

Labels (1)
0 Kudos
(7) Replies
Jenifer
Flexera Alumni

Hi,

 

You can implement this by writing installscript code.Here are some information that can help:

  • You can detect specific  website's installation by searching an entry in applicationhost.config(C:\Windows\System32\inetsrv\config\applicationHost.config)
  • Based on website's existence,you can set INSTALLDIR property of website as <New Value> or existing value( c:\inetpub\wwroot\)
  • You can try setting IIS properties using MsiSetProperty/TextSubSetValue as mentioned in the below article:

https://helpnet.flexerasoftware.com/installshield20helplib/Content/helplibrary/IIS-MSIProps.htm

 

Hope it helps,

Thanks,

Jenifer

0 Kudos

Hello Jenifer,

Thank you for your reply. I have been testing your suggestions.

Based on my testing, I have a few more questions:

1) Is there an API in install script to retrieve the web site information from applicationhost.config ?
2) May you please show me an example on how to reset the INSTALLDIR to a new value?
3) If I created an Website in MyWebSite and the web app is MyApp in Installer Designer/Server Configuration/Internet Information Service, how can I retrieve this WebSite in InstallScript and set the MyWebSite to a new name such as "MyWebSite2"?
4) Based on my testing, it seems like that I have to set the "MyWebSite" to be a new site number to create it during installation. If I set the SiteNumber to be "0", it treats it as the "Default Web Site". I tried to set it to be the "INSTALLSHIELD_IIS_NEXT_NEW_SITE_NUMBER", it did not work. It throw an error during installation. How should I get the next number and how can I set this number in the script code?
5) Based on my testing, to be able to create a new site and make the new site accessible, I also need to modify the C:\WINDOWS\System32\drivers\hosts file to add the new site to this file. Does Install Shield provide an API to modify this file?

Thank you for your help.

0 Kudos

Hi @AceBear ,

 

Answering to your questions:

Is there an API in install script to retrieve the web site information from applicationhost.config ?-No,you can have Managed custom action to this job via writing .Net dll that can read values from it.Some links to help you with:

Note:You can also achieve it via VBScript custom action by writing VB code,i had attached sample vbscript files which will create IIS-Virtual directory and Set properties.You can refer the same for application/website creation.Follow the instructions given in file.

May you please show me an example on how to reset the INSTALLDIR to a new value?:

  • You can create a new property entry named Eg:CustomINSTALLDIR under Property table by navigating to Direct Editor->Property
  • Give the newly created property entry inside angular bracket <CustomINSTALLDIR> under your application content Source path as <IISROOTFOLDER>\<CustomINSTALLDIR>
  • Inside your script,try setting the value using the function 
    • string svDirValue;//Which ever value you want to set based on condition check from ApplicationHost.config
    • TextSubSetValue("<CustomINSTALLDIR>",svDirValue, TRUE ); 
  • This will do the job for you.

If I created an Website in MyWebSite and the web app is MyApp in Installer Designer/Server Configuration/Internet Information Service, how can I retrieve this WebSite in InstallScript and set the MyWebSite to a new name such as "MyWebSite2"?:

  • You are only creating website know,why do you want to change the value?

Based on my testing, it seems like that I have to set the "MyWebSite" to be a new site number to create it during installation. If I set the SiteNumber to be "0", it treats it as the "Default Web Site". I tried to set it to be the "INSTALLSHIELD_IIS_NEXT_NEW_SITE_NUMBER", it did not work. It throw an error during installation. How should I get the next number and how can I set this number in the script code?

 Based on my testing, to be able to create a new site and make the new site accessible, I also need to modify the C:\WINDOWS\System32\drivers\hosts file to add the new site to this file. Does Install Shield provide an API to modify this file?

  • You can use installshield's Internet Information Services.Why do you want to create by your own from code?InstallShield doesn't provide any API to do this.

 

Thanks,

Jenifer

 

0 Kudos

Hello Jenifer,
Thank you very much for these information. It is very cool. I will dig into it.  I am sure that I will have a few more questions later.
0 Kudos

It seems that there are two ways to set a property:

MsiSetProperty(ISMSI_HANDLE, "IS_UPGRADE_INSTALL", "2"); // 1: New Install; 2: Upgrade
TextSubSetValue("<IS_UPGRADE_INSTALL>","2", TRUE );

What are the difference between these two? 

How to display a property in a message box?

0 Kudos

Hello Jenifer,

I have two Directories defined in the Directory table: MY_INSTALL_DIR1, MY_INSTALL_DIR2.

Based on the condition, I want to set MY_INSTALL_DIR1 to be MY_INSTALL_DIR2. I cannot hard code the MY_INSTALL_DIR2 because it is a sub folder under /Program Files.

I tried the following two ways but neither worked:

Option 1) TextSubSetValue("<MY_INSTALL_DIR1>","<MY_INSTALL_DIR2>", TRUE );

Option 2) MsiGetProperty(ISMSI_HANDLE, "MY_INSTALL_DIR2", szValueBuf4, cchValueBuf); 

    MsiSetProperty(ISMSI_HANDLE, "MY_INSTALL_DIR1", szValueBuf4); 

How to really set MY_INSTALL_DIR1 to be MY_INSTALL_DIR2 in InstallScript?

What is the relationship between Property object and Directory object? How to assign a Directory value to a Property?

 

 

 

0 Kudos

Hi @AceBear ,

 

 

How about saving those values in property itself and making use of function FeatureSetTarget by following guidelines in the below article:

https://community.flexera.com/t5/InstallShield-Knowledge-Base/Creating-a-Custom-Destination-Path/ta-p/3892

 

  • Create two custom folders as mentioned in above article
  • Try setting public properties based on your need
  • Get property and set it to custom directory that you had created before

Sample code would be:

MsiGetProperty (ISMSI_HANDLE , "dirproperty", svPropName, nSize);
FeatureSetTarget ( MEDIA , "MY_CUSTOM_PATH" , svPropName );

 

Thanks,

Jenifer

 

0 Kudos