Archive: Set DEFAULT installation Dir (conditionally)


Hi,

Currrently I have a product whose default installation directory defaults to "C:\PROGRAM FILES\SITECOPY".

What I want is to set it to "C:\PROGRAM FILES\SITECOPY" if the user is on Windows NT/2000 (and probably XP) and to "C:\SC" if on DOS versions (95/98/ME). I want this to be the default that is shown in the choose directory dialog so the user can still place the files where they wish.

Can someone please tell me how I can do this.

Thanks for any help,
Dennis


Sure, just add the following lines to your .nsi file:


Function .onInit
ReadRegStr $0 HKLM "Software\Microsoft\Windows NT\CurrentVersion" SystemRoot
StrCmp $0 "" 0 NoWin9x
StrCpy $INSTDIR C:\SC
NoWin9x:
FunctionEnd


What this does it check for HKLM\Software\Microsoft\Windows NT\CurrentVersion\SystemRoot, and if it is not empty, it knows it is on Windows NT, and skips the StrCpy line.

Note that if you also want to use InstallDirRegKey (to let the user upgrade easily), and don't want to overwrite that install dir if the user is upgrading, you can use something like:


Function .onInit
StrCmp $INSTDIR "C:\Program Files\SITECOPY" 0 NoWin9x
ReadRegStr $0 HKLM "Software\Microsoft\Windows NT\CurrentVersion" SystemRoot
StrCmp $0 "" 0 NoWin9x
StrCpy $INSTDIR C:\SC
NoWin9x:
FunctionEnd


Which will only change $INSTDIR if the default (C:\program files\SITECOPY) is used..

-Justin

Excellent, thanks.


Hi Justin,

I was thinking about your response, it solved my main problem (works very well - thanks) but it would be nice if all the main options such as "DirText" could also be accessed as variables. And please if you do this either add $COMSPEC or access to environment variables in general.....

Bye
Dennis