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

Create a shortcut using installscript based on user input and delete the shortcut on uninstalling the installer

Create a shortcut using installscript based on user input and delete the shortcut on uninstalling the installer

Introduction

This article will discuss how to create a  shortcut based on user input using a property value and Create a shortcut using installscript and delete the shortcut on uninstall

Instructions

     This article explains how to  create a shortcut based on user request. This information applies to the following InstallShield project types:

  • Basic MSI
  • Installscript MSI

Steps to create a Project:

  1. Create Basic MSI Project
  2. Add a Feature and add component and files inside component
  3. Add exe files to component for which we want to create a shortcut.
  4. Go to installscript view and Right and add Setup.rul
  5. Copy paste the code at the bottom of this article into setup.rul (Replace shortcut name as per your exe added in components Example: Notepad.exe)
  6. Make sure CreateShortCut and DeleteShortCut functions are added
  7. Go to CustomAction view and add 2 Installscript Custom Actions and rename it.(CreateShortcut,DeleteShortcut)
  8. For Create Shortcut CA select the function CreateShortcut  and for Delete Shortcut CA select the function name as DeleteShortcut from drop down
  9. Set the Condition for both Customaction (for EX: Create shortcut add condition NOT installed, and for Delete Shortcut add REMOVE~="ALL")CA condition and function.JPG
  10. And select Install Exec sequence as required.
  11. Go to Dialogs and Add a new Interior Dialog dialog 
  12. Go to property manager and add 2 property DESKTOP_SHORTCUT and START_MENU_SHORTCUTProperty added.JPG
  13. Make sure the value column is empty, so that the checkbox is unchecked by default
  14. Rename the new dialog (Example: ShortcutDialog)
  15. And add 2 checkbox like shown belowShortcut checkbox.JPG
  16. And set above created 2 property to this 2 checkbox filedshortcut property assign.PNG
  17. Now Sequence the new dialog (ShortcutDialog) BACK and NEXT button as needed under behavior.
  18.  EX: BACK --> Customer information , NEXT button to Setup Type
  19. Similarly in Customer information Dialog the NEXT Button should be change to ShortcutDialog
  20. Save and build the project
  21. Install the setup.exe and click NEXT and go to Shortcut checkbox dialogShortcut Dialog on runtime.JPG
  22. Click NEXT and Complete Installation
  23. Check shortcut created under desktop and under Appdata folder (EX: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\CompanyName)

 

 

 

 

#include "ifx.h"

export prototype CreateShortCut(HWND);
export prototype DeleteShortCut(HWND);

function CreateShortCut(hMSI)
STRING szShortcutFolder, szName, szCommandLine, szWorkingDir ;
STRING szIconPath, szShortCutKey,szValue,szValue1;
STRING szProgram, szParam, szFolderDir,szCmd;
NUMBER nIcon, nFlag, nResult, nvBufferSize;

begin

//Get Supportdir for icon


szIconPath = WINDIR  ^ "regedit.exe";

//szIconPath = sMySUPPORTDIR +"\\" + "icon32.ico";

szShortcutFolder = FOLDER_DESKTOP;
szName = "DesktopShortcut";
szCommandLine = INSTALLDIR ^ "Notepad2.exe";
LongPathToQuote (szCommandLine, TRUE);

szWorkingDir = "";
nIcon = 1;
szShortCutKey = "";
nFlag = CS_OPTION_FLAG_REPLACE_EXISTING|CS_OPTION_FLAG_RUN_MINIMIZED;


 
 MsiGetProperty(hMSI,"DESKTOP_SHORTCUT",szValue,nIcon);
 
 
if ( szValue == "1") then
	Delay (2);
// Create the folder shortcut, and show the folder it points to.

	if ( CreateShortcut(szShortcutFolder, szName, szCommandLine,szWorkingDir, szIconPath, nIcon, szShortCutKey,nFlag) < 0) then
		Delay (1);
		MessageBox ("DESKTOP Shortcut Not Created.", SEVERE);
endif;
	endif;

//Creating StartMenu Shortcut
szIconPath = INSTALLDIR ^ "Explorer.exe";
szShortcutFolder = FOLDER_STARTMENU ^ "Programs\\CompanyName";
szName = "StartmenuShortcut";
szCommandLine = INSTALLDIR ^ "Uno.exe";
LongPathToQuote (szCommandLine, TRUE);

szWorkingDir = "";
nIcon = 1;
szShortCutKey = "";
nFlag = CS_OPTION_FLAG_REPLACE_EXISTING|CS_OPTION_FLAG_RUN_MINIMIZED;

	
	
	
	 MsiGetProperty(hMSI,"START_MENU_SHORTCUT",szValue1,nIcon);
	 
if ( szValue1 == "1") then
	Delay (2);
// Create the folder shortcut, and show the folder it points to.

	if ( CreateShortcut(szShortcutFolder, szName, szCommandLine,szWorkingDir, szIconPath, nIcon, szShortCutKey,nFlag) < 0) then
		Delay (1);
		MessageBox ("STARTMENU Shortcut Not Created.", SEVERE);
endif;
	endif;
	
end; 

//Script to delete shortcut on uninstallation.
function DeleteShortCut(hMSI)
#define shortcutName "DesktopShortcut"
#define shortcutName1 "StartmenuShortcut"
STRING szCompany,szStartMenuPath,startMenuShortcut,szDesktop,szDesktopShortcut;
STRING nvSMProp,nvDesktopProp;
NUMBER nBuffer;

begin

	nBuffer = MAX_PATH + 1;
	szDesktop = FOLDER_DESKTOP;

	
	szDesktopShortcut = INSTALLDIR ^ "Notepad2.exe";
	
	
	if (Is(FILE_EXISTS, szDesktopShortcut) = FALSE) then
	Delay (1);

	DeleteShortcut(szDesktop, shortcutName);
	
	else
	
	MessageBox("No shortcut to delete", INFORMATION);
	endif;
	
	
szCompany = FOLDER_COMMON_APPDATA + "Microsoft\\Windows\\Start Menu\\Programs\\CompanyName\\";	

if (Is(FILE_EXISTS, szDesktopShortcut) = FALSE) then
	Delay (1);

	DeleteShortcut(szCompany, shortcutName1);
	
	else
	
	MessageBox("No shortcut to delete", INFORMATION);
	endif;
	
	
end;

 

 

 

More Information

Click here for installscript help documentation on create shortcut

Click here for installscript help documentation on delete shortcut

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Oct 27, 2023 04:33 AM
Updated by:
Contributors