Monthly Archives: October 2014

Installshield: Prompt user for a license file, then copy it

Project:

I need to add a prompt to an installshield project that asks the user where the license key file is, then copy the file to the INSTALLDIR location.

This is going to be a fairly complex thing, First I am going to create an install script function that copies the file, then I am going to create two custom actions, one that executes the CopyLicenseFile installscript file, the other prompts for the File location using  a file browser. Then I am going to create a new dialog that will call the FileBrowse custom action.

I am assuming you have already created a basic MSI project.

References

I used the following references

http://helpnet.installshield.com/installshield16helplib/IHelpIScriptEntryPoint.htm

http://helpnet.installshield.com/installshield18helplib/mergedProjects/installshield18langref/LangrefCopyFile_Example.htm

http://helpnet.installshield.com/installshield16helplib/AccessingProps-DeferredCAs.htm

http://helpnet.installshield.com/installshield16helplib/FileOpenDialog-HowTo.htm

InstallScript

Expand out Behavior and Logic, and click on InstallScript

Click on the Installscript, then right click on Files and choose New Script File

Comment out the same code

//export prototype MyFunction(HWND);

 

///////////////////////////////////////////////////////////////////////////////
// 
// Function: MyFunction
// 
// Purpose: This function will be called by the script engine when
// Windows(TM) Installer executes your custom action (see the "To
// Do," above).
// 
///////////////////////////////////////////////////////////////////////////////
//function MyFunction(hMSI)
 // To Do: Declare local variables.
//begin

 // To Do: Write script that will be executed when MyFunction is called.

//end;

We are going to create an extry point function called ExFn_CopyLicenseFile Copy and Paste into the Setup.rul,

#include "ifx.h"
///////////////////////////////////////////////////////////////////////////////
// 
// Function: ExFn_CopyLicenseFile
// 
// Purpose: This function will be called by the script engine when
// Windows(TM) Installer executes your custom action (see the "To
// Do," above).
// The Function reads from the Property LICENSEFILE and INSTALLDIR, then copies the
// file LICENSEFILE to INSTALLDIR/LICENSEFILE
// 
///////////////////////////////////////////////////////////////////////////////
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_CopyLicenceFile(HWND);
function ExFn_CopyLicenceFile(hMSI)
 NUMBER nResult;
 STRING licenseFilePath;
 NUMBER licenseFilePathBuffer;
begin
 licenseFilePathBuffer = MAX_PATH;
 if(MsiGetProperty(hMSI, "LICENSEFILE", licenseFilePath, licenseFilePathBuffer) == ERROR_SUCCESS) then
 SprintfBox(INFORMATION,"Deferred Execution","The value of LICENSEFILE is %s",licenseFilePath);
 SprintfBox(INFORMATION,"Deferred Execution","The value of INSTALLDIR is %s",INSTALLDIR);
 endif;

 // Copy all files in the source directory, including files
 // in subdirectories, to the target directory.
 nResult = CopyFile(licenseFilePath, INSTALLDIR + "license.lic"); 
 // Report the results of the copy operation.
 switch (nResult)
 case 0:
 MessageBox ("File successfully copied.", INFORMATION);
 case COPY_ERR_CREATEDIR:
 MessageBox ("A target directory could not be created.", SEVERE);
 case COPY_ERR_MEMORY:
 MessageBox ("Insufficient memory.", SEVERE);
 case COPY_ERR_NODISKSPACE:
 MessageBox ("Insufficint disk space.", SEVERE);
 case COPY_ERR_OPENINPUT:
 MessageBox ("Unable to open the input files in "+ INSTALLDIR +".",
 SEVERE);
 case COPY_ERR_OPENOUTPUT:
 MessageBox ("Unable to copy the source files.", SEVERE);
 case COPY_ERR_TARGETREADONLY:
 MessageBox ("A target file already exists and cannot be overwritten.",
 SEVERE);
 default:
 MessageBox ("An unspecified error occurred.", SEVERE);
 endswitch;
end;

I have left in the MessageBox and the SprintfBox lines to aid in debugged, and would be removed for your production version.

You should now have file -> Setup.rul and Functions -> ExFn_CopyLicenseFile

Custom Actions

Expand out Behavior and Logic, then click Custom Actions and Sequences

Right click on Custom Actions and choose New InstallScript

Change name to “CopyLicenseFile”

Set ‘Function Name’ to ExFn_CopyLicenseFile

Set install Exec Sequence to After MsiConfigureService

Set the ‘Install Exec Condition’ to ‘NOT Installed AND NOT PATCH’ this will mean it only runs if the Product is not installed and this isn’t a Patch

Create another Custom action, New MSI DLL, Stored in Binary Table

Rename to FileBrowse

 

In the right hand pane

DLL Filename: <ISProductFolder>\redist\language independent\i386\FileBrowse.dll
Function Name: FileBrowse
Return Processing: Synchronous (Ignores exit code)
In-Script Execution: Immediate Execution
Execution Scheduling: Always execute
For all other settings, leave the default values. The value of the MSI Type Number setting should be 65.

Create Properties

Expand out Behavior and Logic, and click on Property Manager

Click on New

Rename to LICENSEFILE, since this starts with a CAPITAL it creates a global property that can be referenced later.

Create another IS_BROWSE_FILEBROWSED

Create Custom Dialog

Expand out User Interface and click on Dialogs

Find the DestinationFolder Dialog,

Right Click and clone

Rename to LicenseFileLocation

We are doing to repeat the following steps for a number of resources, the goal is to create a new STRING property for each string we are changing, so we don’t accidentally change the strings in other dialogs.

Click on LicenFileLocation, English (United States)

Click on the string Destination Folder so it is highlighted

Click in the Text field where is says Destination Folder

Click on the …

Then Cick on New

Change Value to License File

Repeat for “Click next to install

 

Change Text to “Click Next to install, or click Change to change the source of the License File”, remember to do the three dot and then new to create a new string, or you will also change the value in the dialog you cloned.

Change “Install [ProductName] to:” to “Install [ProductName] License File:”

Click on  [INSTALLDIR]

Change Property to LICENSEFILE

Change Text: to [LICENSEFILE], remeber the three dots and create new string

Click on LicenseFileLocation -> Behavior

Click on ChangeFolder

Change SpawnDialog to DoAction, and Argument to FileBrowse

Change [_BrowseProperty] to [LICENSEFILE] and Argument to [IS_BROWSE_FILEBROWSED]

Click on Back

Change NewDialog to “Destination Folder”

Click on DestinationFolder -> Behavior

Click on Next

Change NewDIalog to LicenseFileLocation

Click on SetupType -> Behavior

Click on Back

Change NewDialog to LicenseFileLocation

Test

Now the moment of truth, build and test, Why are not setting a default license file so it is pulling the default value from the property which is “0”

Click on Change…

 

Succcess 🙂

Installshield Register.Net DLLs

My task is I need to register  a .net dll as part of the install.

First thing I am going to do is Create a Basic MSI Project

Approach 1

Create a component with just the .net dll in it

Make sure you have clicked the Installation Designer Tab, then expand out ‘Organization’, then select ‘Setup Design’, then select TestDLLRegister_Files

Right Click, choose ‘New Component’

Now expand out TestComonent, and choose ‘Files’

right click and choose ‘Add’ and select the dll you want to register.

Now it should show up in the files listing.

To set the .dll to be the keyfile, select the dll, then choose ‘Set Key File’

You will now see the key icon next to the DLL

Click on TestComponent

You should see

Change the .net Interop to yes

Installshield in the background is using regasm /regfile to create a file that contains the registry changes needed, then includes those changes as part of the install.

For some reason, perhaps that I am installing a 32bit component on a 64bit machine, this didn’t work as expected. After install the target machine contained all the registry enteries that the regasm /regfile creates but it didn’t work, I have read that some DLL’s perform post registration actions the run when you run RegAsm.exe VirtualCam.dll /nologo /codebase but don’t get captured when you run RegAsm.exe VirtualCam.dll /nologo /codebase /regfile

Approach 2

Run a .bat file to register the files.

Create 2 batch files, one that registers the dll and the other that unregisters

Install.bat
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe VirtualCam.dll /nologo /codebase

uninstall.bat

C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /unregister /nologo VirtualCam.dll

Create a new Component

Expand out the new component you created Test2Comonent, and click on ‘Files’

Add files

Make sure it will install your files to [INSTALLDIR] by clicking on Test2Component and checking it says ‘Destination’ ‘[INSTALLDIR]’

Expand out ‘Behavior and Logic’ and choose ‘Custom Actions and Sequences’

Right click on custom actions

Choose new exe -> Path references a file

Set ‘Working Directory’ to ‘INSTALLDIR’

Set ‘File Name & Command LIne’ to ‘[SystemFolder]cmd.exe /c /install.bat’

Set ‘Return Processing’ to  ‘Syncronous (Check exit code)’

Set ‘In-Script Execution’ to ‘Immediate Execution’

Set ‘Execution Secheduling’ to ‘Always execute’

This should give you an MSI type of 34

Change the Install Exec Sequence to ‘After InstallFinalize’

Set the ‘Install Exec Condition’ to ‘NOT Installed AND NOT PATCH’ this will mean it only runs if the Product is not installed and this isn’t a Parch

Rename the Custom Action to ‘RegisterDLL’

Repeat for  UnRegisterDLL, except this time you are executing uninstall.bat

This time the ‘Install Exec Sequence’ is “After RemoveIniValues’ and ‘Install Exec Condition’ is “Remove ~=”ALL” so this runs only when all components have been removed and the app is being uninstalled.

Now Assuming everything worked you will see the black dos box during the install and your DLL will be registered.

Create a Basic MSI Project

Choose Basic MSI, enter a project Name, Enter  location

Click on Application Information

Enter your Company Name, and Company Web address

Click on Installation Interview

Do you want to display a License Agreement Dialog: No

Do you want to prompt users to enter their Company Name and User Name: No

Do you want your user to be abel to modify the installation location of your application: Yes

Do you want users to be able to selectively install only certain parts of your application: Yes

Do you want to give users the option to launch your application when the installation completes: No

Choose Build Installation

Choose Single Executable

Build Installations

Click on Installation Designer

Change the INSTALLDIR to remove the Inc. from the name

Change the Project File Format to XML, I always do this so I can track changes to the installer file in source control like git