Archive: Either launch install or launch app?


Either launch install or launch app?
I'd love to have my CDROM autoplay and then check the registry to see if my app is already installed.
It should then run the installer if not installed, or run the app if already installed.

Is this possible with NSIS? I've searched around but I'm starting to think this is not possible.

Any suggestions on how to accomplish this much appreciated!


Yes, this is very possible.

First, you should know how to autorun the app. If you don't, then I can tell you later.

Second, In the .nsi script type the following example, but replacing it with your appropriate coding:

InstallDirRegKey HKCU MyApp ""
InstallDir "$PROGRAMFILES\MyAPP\"


The Reg key will replace the InstallDir with what the user has placed instead.

Hope this helps
-Duane

Thanks Duane. It's the "now that I know the app is installed, dont run the NSIS installer, but run the app instead" part that I can't seem to get to work. I do have the app launching after the install is complete just fine.


Do something like this:

InstallDir $PROGRAMFILES\MyApp

function .onInit
ReadRegStr $0 HKLM "Software\MyApp" "InstallPath"
StrCmp $0 "" Done
Exec "$0\MyApp.exe" it is installed! so run the program!
Quit
Done: ; So not installed? continue install then!
functionend

section
; some install stuff
sectionend

section ; do not forget to write the regkey
; to know next time that it is installed
WriteRegStr HKLM "Software\MyApp" "InstallPath" "$INSTDIR"
sectionend

To autorun, create a file "autorun.inf" containing this:
[autorun]
open="path to app" ; replace!
icon="icon file" ; replace!


Good luck,
-Hendri.

Thanks
Thanks! Not having the code in an .onInit function is where I was messed up!


I would prefer checking the if the file exist (fileexist) instead of the registry. If the user has deleted the file, then that method would fail to exec it.


Yes, you need to perform a FileCheck before execution. But running from CD, we cannot do without the registry since we don't know where the app has been installed.

-Hendri.


Just wondering, can't you just check the registry key to see if it exists? If it doesn't, then the app wouldn't have been installed


Originally posted by rainwater
If the user has deleted the file, then that method would fail to exec it.
Mlbl, that's the reason for the FileCheck!

-Hendri.

Originally posted by Smile2Me
Mlbl, that's the reason for the FileCheck!

-Hendri.
I don't see a filecheck in that function.

Originally posted by Smile2Me
Yes, you need to perform a FileCheck before execution. But running from CD, we cannot do without the registry since we don't know where the app has been installed.

-Hendri.
It needed to be added indeed, I just quoted you to show that the code needed some work, so:
InstallDir $PROGRAMFILES\MyApp

function .onInit
ReadRegStr $0 HKLM "Software\MyApp" "InstallPath"
StrCmp $0 "" Done
IfFileExists "$0\myapp.exe" 0 errorquit
Exec "$0\MyApp.exe" ; it is installed! so run the program!
Quit
ErrorQuit:
MessageBox MB_OK "You stupid man! You deleted the program! ERROR!"
Quit
Done: ; So not installed? continue install then!
functionend

section
; some install stuff
sectionend

section ; do not forget to write the regkey
; to know next time that it is installed
WriteRegStr HKLM "Software\MyApp" "InstallPath" "$INSTDIR"
sectionend

Wouldn't this be better:


InstallDir $PROGRAMFILES\MyApp

function .onInit
ReadRegStr $0 HKLM "Software\MyApp" "InstallPath"
StrCmp $0 "" Done
IfFileExists "$0\myapp.exe" 0 Done
Exec "$0\MyApp.exe" ; it is installed! so run the program!
Quit
Done: ; So not installed? continue install then!
functionend

section
; some install stuff
sectionend

section ; do not forget to write the regkey
; to know next time that it is installed
WriteRegStr HKLM "Software\MyApp" "InstallPath" "$INSTDIR"
sectionend



I would think you would want the installer to run if the file is not there.

My solution is intended to run the program on harddisk if installed. Otherwise the installation will continue. So no aditional installation needed that should be run. My solution prouces a small exe can be put on CD, autorun and work as installer or as program starter.

-Hendri.


Originally posted by Smile2Me
My solution is intended to run the program on harddisk if installed. Otherwise the installation will continue. So no aditional installation needed that should be run. My solution prouces a small exe can be put on CD, autorun and work as installer or as program starter.

-Hendri.
I'm not sure I understand. If the user's registry key doesnt get deleted when the program was removed, your solution would fail to install the application. Correct?

So indeed, we need a proper uninstall, but that was not he question :)

-Hendri.


A solution to the problem that people delete applications instead of uninstalling them could be this: if no regkey -> just install. If the regkey is present -> present an InstOpts dialog asking to "reinstall" or "run" (and maybe even "uninstall") and where run is default. This way this problem would have been solved.

-Hendri.