Archive: Previous installation directory


Previous installation directory
  Hello,

I have an app called XXX.

Using NSIS, I have installing it in \Program File\XXX.

Now we are coming out with two editions of XXX. XXX Enterprise and simple XXX.

I am creating the installer using NSIS (version I am not sure but if required i can download NSIS 2.02). Now I want to check whether \Program Files\XXX exists or not. If it exists then I would like to install both Enterprise and Basic version in XXX otherwise I would like to install in \Program Files\XXX Enterprise or \Program Files\XXX Basic whichever the case maybe?

How can I check whether \XXX exists and how to go about with it?

Regards,
RiteshN


Read NSIS Help description of:
InstallDir
InstallDirRegKey
and use something like this
WriteRegStr HKCU "${REG_PATH}" "${INST_DIR}" "$INSTDIR"


Sorry but I am still confised. I read the docs but I am unable to understand how to replace current installation.

This is a required part from my current nsis script:


HM NIS Edit Wizard helper defines

>!define PRODUCT_NAME "XXX"
>!define PRODUCT_VERSION "1.0"
>!define PRODUCT_PUBLISHER "Me"
>!define PRODUCT_WEB_SITE "http://www.me.com"
>!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\xxx.exe"
>!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
>!define PRODUCT_UNINST_ROOT_KEY "HKLM"

>Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
>OutFile "G:\\output\\xxx.exe"
>InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
>InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
>ShowInstDetails show
ShowUnInstDetails show
>
as I see in my new scripty I will have something like the following:


HM NIS Edit Wizard helper defines

>!define PRODUCT_NAME "XXX Enterprise"
>!define PRODUCT_VERSION "2.0"
>!define PRODUCT_PUBLISHER "Me"
>!define PRODUCT_WEB_SITE "http://www.me.com"
>!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\xxxent.exe"
>!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
>!define PRODUCT_UNINST_ROOT_KEY "HKLM"

>Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
>OutFile "G:\\output\\xxxent.exe"
>InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
>InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
>ShowInstDetails show
ShowUnInstDetails show
>
But I am unable to understand where to check whether XXX is already installed then use the current installation directory otherwise use "$PROGRAMFILES\${PRODUCT_NAME}" i.e. XXX Enterprise or XXX Basic.

A sample script will be very helpful.

1. Use correct registry paths with slashes
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Pathsxxx.exe"
The same for uninst key.

2. Try to read this value from registry at the beginnig of installation. If this is first installation you will get error. For example
ReadRegStr $0 HKLM "${PRODUCT_DIR_REGKEY}" ""


1. Use correct registry paths with slashes
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Pathsxxx.exe"
The same for uninst key.
I am using slashes but when I pasted it as code out here, the board didnt like it :)

Try to read this value from registry at the beginnig of installation. If this is first installation you will get error. For example
ReadRegStr $0 HKLM "${PRODUCT_DIR_REGKEY}" ""
OK. understood a little. But how do I handle the error and proceed?

Thanks for your patience.

Regards,
Karam

MessageBox, Abort.

Use [code] not [php]

-Stu


I will try to make myself more clear.

In my previous script i had:


!define PRODUCT_NAME "XXX"
!define PRODUCT_VERSION "1.0"
PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\XXX.exe"
!define PRODUCT_DIR_REGKEYENT "Software\Microsoft\Windows\CurrentVersion\App Paths\XXX.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "G:\output\xxx.exe"
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show


This means by default it will install XXX in \\Program Files\\XXX folder or if the user changes it while installation. In the registry, the uninstallation folder is also kept as \\Program Files\\XXX. I have been creating upgrades to my app in the same way. Therefore if a user upgraded then NSIS automatically detected the previous installation. I think it was due to the fact that my product name was always XXX till now.

Now I am having two editions: XXX and XXX Enterprise. As I see, I wont have any problems with XXX as it will recoginise the previous installation.

I am having difficulty with XXX Enterprise. If I put the PRODUCT_NAME as XXX Enterprise, it is doing a complete new installation even if XXX is installed before i.e. \\Program Files\\XXX Enterprise coz it is not matching with XXX.

Also, the binary name has changed from XXX to XXXEnt.exe so the shortcut in the program menu also needs to be changed.

Hope this sheds more light on the matter.

Originally posted by Afrow UK
MessageBox, Abort.

Use [code] not [php]

-Stu
I dont want to abort. Gives wrong impression to the user :(

Function .onInit
Push $R0

ReadRegStr $R0 "Software\Microsoft\Windows\CurrentVersion\App Paths\XXX.exe" ""
StrCmp $R0 "" +3
MessageBox MB_OK "${PRODUCT_NAME} already installed"
Abort

Pop $R0
FunctionEnd


Is that the general thing you want?

-Stu

No.

What I want is that if XXX is installed then XXX Enterprise also gets installed in same directory as XXX otherwise, it should do a new installation as XXX Enterprise.

Therefore, I have to basically change the installation directory during the installation process :)


That is already the default behavour.
If no registry value is found for InstallDirRegKey then the InstallDir value is used instead.

-Stu


I am aware of this feature and it works great for me.

My problem is that with XXX Enterprise, my product name is XXX Enterprise and it being first release will never be present in anybodys computer. It will always create a new one. What I want is that if it finds XXX (which was being used till date) then it should install in XXX folder rather XXX Enterprise as it will happen normally.

I guess - I am not able to make myself clear.


So why doesn't this work?

InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\App Paths\XXX.exe" ""
InstallDir "C:\Program Files\XXX Enterprise"


-Stu

Nope. It dosnt work.

Here is a sample of my nsi:


!define PRODUCT_NAME "XXX Enterprise"
!define PRODUCT_VERSION "4.0 RC 1"
!define PRODUCT_PUBLISHER "MyCompany"
!define PRODUCT_WEB_SITE "http://www.me.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\XXXEnt.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

...
...

InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\App Paths\XXX.exe" ""


In this case even if my previous version of XXX was installed, by the default the installation directory is always shown to be XXX Enterprise. I want to keep it XXX if XXX is installed.

BTW, the following code:


CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\XXXEnt.lnk" "$INSTDIR\XXXEnt.exe"


is also not creating creating a menu under All Programs. Am I doing something wrong as it was previously working?