Archive: Install var in uninstall


Install var in uninstall
  Hi,

I define and use an install-time variable with Var that I use in the installer. Now I would like to use this value also in the uninstaller (with the value that it was given during the install). Is it possible to accomplish this in some way?

Thanks,
Torbjörn


Hi :)

To achieve that, you'll have to write the value of that variable into an 'ini' file, and read that variable from the uninstaller.

- In the installer:

WriteIniStr"c:\\my_dir\\my_file.ini" "MySection" "MyVarValue" $MyVar 

>

- In the uninstaller:

ReadINIStr $MyVar "c:\\my_dir\\my_file.ini" "MySection" "MyVarValue" 

evilO/Olive

Thanks, it works great!


Using the registry is faster than using an INI file.


True. I guess I'm too used to the 'ini' files as I have plenty of information to store and to retrieve :D..
Therefore I use the registry a less as possible, let's say the installation directory and the usual "Uninstall" keys...

evilO/Olive


Install vars in uninstall
  Excuse me, but i tried to do something similar and i hit the classic "cat chasing his tail" problem.

To be short, i'd lke to use the installer to build some dynamic directory structures that based in a common root, may have some common nodes, whose names are depending on some parms entered in a configuration page and dinamically build the related uninstallers that when invoked delete the related structure, starting from the leafs up to the point where the nodes are shared with other structures.

The uninstaller names are dynamically generated depending on parms entered in a configuration page, but given the fact that i cannot pass the installer variables directly into the uninstaller, and i find this a truly bad limitation, i was not able to find any means to link a generated uninstaller with a generated ini file or registry keyword.

I need some dynamic values in the uninstaller, but i cannot read them because i need another dynamic value to point me to the saved ini file or registry keys that contains them.

I tried to use the
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
call to get the uninstaller name, to use is as the name of a related ini file, but what i get back is the name with which the uninstaller copies itself into the temporary directory.

Using that returned name, after cutting away the temp dir part, doesn't allow me to even retrieve the original installer to delete it, so it's completely useless.

Do you think there's a way to solve this or i have to abort the idea to use NSIS to perform this job?

Thanks, Gabriele


$EXEDIR.


Install vars in uninstall
  What exactly do you mean?
$EXEDIR in a uninstaller returns the
windows TEMP directory path, in short format.
What can i do with that?

Gabriele.


Oops. It's $INSTDIR or $OUTDIR.


Hi kichik,
thanks for you fast response, but from it i guess you didn't understand my problem:)
I don't want to bother you again with the details, since i found myself a bypass for the problem.
I write a uninstall.exe and uninstall.ini in a leaf of the generated structure, so that they can be always written with the same name and uninstall.exe is able to find its ini file using a static name instead of a dynamic one.
Then i write a shortcut to it with the generated name in the common $INSTDIR.

Anyway my perplexities still remain, and since before answering i spent some more time peeking around in this forum, i see i'm not alone.

We can create really powerful and customized self contained installers, using variables, but we cannot pass a bit of these information into uninstaller unless we start polluting registry or filesystem with ini files and making strange contorsions like in my case.

I guess it's not a technical problem, it shouldn't be too difficult to replicate the variable symbol table or whatever you use in your compiler, into the generated uninstaller, but rather a design choice.

If your concerns are about avoiding that users may uninstall something wrong giving them too much power, i can assure you that i work since 26 years in IT, i have worked with almost all OS that have been invented and with almost all the languages that have been conceived and i have seen generations of designers striving to build foolproof products.
No way, fools are, and will always be, more clever than them and will always find a way to shoot themselves in their feets, no matter what you give in their hands.

So please make all the variables created in the installer available into the uninstaller and give us the power to kill ourselves at our pleasure without too much fatigue:)

Thanks Gabriele.


Hi Gabriele,

Well stated. I agree with you. The uninstaller would become much more robust if it could use the values of variables as declared in the installer. The uninstaller would achieve greater independence, no longer having to necessarily rely on the registry or INI files to restore the values of needed variables.


You wanted to get the directory that contained the uninstaller. $INSTDIR contains exactly that.

As for automatically saving all of the variables from the installer in the uninstaller executable, it's very wasteful. You'll add around 30kb (1kb per variable by default). And if you're thinking of compressing it, you'd need to add the compression code to the exehead which will increase both the installer and uninstaller size by a very noticeable amount (not to mention the hard work to get the compression code to lose clib dependency).

If you really want to avoid regitry and INI files, you can always append data to the uninstaller yourself. By default, the CRC checksum stops at the end of the data. You can then read this data using FileRead.


How to append data to the uninstaller?
  Hi,
I want to append data to the unistaller in order to reuse the data in the uninstaller which i defined in the installer. I want to avoid creating an ini file or using the registry for storing such data.

My question now is how to do that in detail.

Can somebody help me with that?

M.


Use FileOpen, FileSeek, FileWrite and FileClose to write data to the uninstaller file. In the uninstaller, use FileRead to get that data. Note that you'll have to disable CRC check for the uninstaller for this to work. Use CRCCheck to do that.


At first - I have read http://forums.winamp.com/showthread....hreadid=249431 and I know how to append data to the uninstaller.

I was trying to do it myself - posting attachment. Everything was OK until I tried to read from the uninstaller file. FileRead instruction set ErrorFlag and I don't know why.

Any suggestions?


$EXEDIR is $TEMP in the uninstaller. Use $INSTDIR instead.


Thanks Kichik, I know that. I thought that it doesn't matter from which location I read the uninstaller. Is the problem that FileRead can't read from the file in $TEMP because it is executed?

Attaching working script:


It can read itself, but the name is different. So you have to use $EXEPATH instead of $EXEDIR\unDataUninst.exe.


Ooops, I forgot this fact. Thank you


Potential solution without writing to file or registry. Sample code attached.
  I found this post while trying to get an answer to the same question the original poster had. I was trying to set/save a string value of the path to a folder somewhere other than the install path (e.g. $INSTDIR or $EXEDIR). I figured out a different way to accomplish my goal. The following methodology may work for some of your situations. I know it worked well for mine. I don't know why, but it worked for my application. Sample code is attached as a text file. Overview: Declare a global variable outside/before sections (e.g. Var /GLOBAL FormsFolder). Set the value of the variable (StrCpy $FormsFolder "F:\Main\Branch\Twig\Forms") in the initialization function, an install section (e.g. Section ""), and the uninstall section (i.e. Section "Uninstall").