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

Automatically set INSTALLDIR to the same value for base version and major upgrade

Automatically set INSTALLDIR to the same value for base version and major upgrade

1. Create a base version with the custom action "SetARPINSTALLLOCATION" (refer to the project settings in the screenshot and alter Install
Exec Condition based on your product needs).

Custom Action.png

Note: The custom action created in the base version will help in setting the INSTALLDIR in the Windows Registry, which will allow you to retrieve the INSTALLDIR when you start installing the major upgrade.

2. Install to the desired path on the target machine, a path other than default path.

3. Now create major upgrade by incrementing the product version (for example, from version 1.0.0 to version 2.0.0), generating a new product code with the ellipsis {…} button, adding a major upgrade item under upgrades and with two new custom actions listed below:

  •  InstallScript custom action with the below settings associated with respective InstallScript code (Please alter Install Exec Condition based on your product needs).

    ReadInstallLoacation.png

     

    InstallScript associated with READINSTALLLOCATION

    Setuprul.png 

    InstallScript code for your reference:

    export prototype ReadInstallLocation(HWND);
    function ReadInstallLocation(hMSI)
       STRING szKey, szName, svValue, svPropertyValue;
       NUMBER nvType, nvSize, nvBufferSize;
    begin
    	RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    	szKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{9D9E6191-A7D8-455A-9177-531471683FC8}";
    	szName = "InstallLocation";
    	nvType = REGDB_STRING;
    	nvSize = MAX_PATH;
    	nvBufferSize = MAX_PATH; 
    	
    	RegDBGetKeyValueEx(szKey,szName,nvType,svValue,nvSize);
    	MessageBox("svValue="+svValue,INFORMATION);
    
    	MsiSetProperty(hMSI,"MYINSTALLLOCATION",svValue);	
    	MsiGetProperty(hMSI,"MYINSTALLLOCATION",svPropertyValue,nvBufferSize);
    	MessageBox("svPropertyValue="+svPropertyValue,INFORMATION);
    end;
    
    ​
    • New Set Directory Custom Action:

      New Set Directory.png
      Now create the build and Install on the target machine it will retrieve the INSTALLDIR of the program and set it as default path automatically during installation of the major upgrade.

      Attached is the sample of the project created for your reference.
Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Sep 16, 2021 11:11 AM
Updated by:
Contributors