Archive: NSIS or Me?


NSIS or Me?
One of us is not getting it and I think it's me...

basically I have a simple function to check if the program being installed has been uninstalled from the same machine. On uninstall, a key is left behind that the installer will check for every time it runs.

The function works correctly for the first install. I get the messagebox that has a blank value for $R0 when it reaches "done:" which it should since nothing has been uninstalled as of yet.

The problem is that it also continues to work after the program has been uninstalled. When I install again, it skips the "$R0 inside" messagebox and shows the string value of "un" ( which is correct ) for "$R0" in the messagebox after "done:".

I'm thinking that if the installer can see the key and copy the value, there shouldn't be an error and the program should abort.

The registry key is definitely in place after the uninstall.

Function checkForUninstall

ReadRegStr $R0 HKLM "SOFTWARE\legacy" "name"
IfErrors done

MessageBox MB_OK|MB_ICONINFORMATION "$R0 inside"
Abort

done:
MessageBox MB_OK|MB_ICONINFORMATION "$R0 pass"

FunctionEnd

I also tried it this way with a similar outcome:

Function checkForUninstall

ReadRegStr $R0 HKLM "SOFTWARE\legacy" "name"
IfErrors done bad

bad:
MessageBox MB_OK|MB_ICONINFORMATION "$R0 inside"
Abort

done:
MessageBox MB_OK|MB_ICONINFORMATION "$R0 pass"

FunctionEnd

Usually this means I'm missing something so simple that it will be painfully obvious to a second set of more savvy NSIS eyes, many thanks for any help

jonny


I tried your function and if the registry key existed (I made it manually using regedit) then the script works fine. See attached script that I tested.


at least I know it's not my code snippet
Thanks sunjammer,
I thought I was going nuts because when I isolate the function it does work. What seems to be happening is that another function is causing it not to work properly even though they are not related functions. This code works in my real program when I comment out the function to check for any current installations of the product, but when I reactivate that function this one decides not to work. I'm going to try a few things with the sequence of events to see if that helps, but I appreciate your input.


The other function is probably causing an error and doesn't clear it. Use ClearErrors before the code block that you wish to check for errors.


ClearErrors did it
Thanks Kichik,

Using ClearErrors did it. I now have a very happy installer that works as it should...