Ok, so NSIS has most the 64 bit functionality available for their installers.
I need to write a registry key to the 64 bit registry on 64 bit machines.
I may need to install to Program Files or Program Files (x86).
If on 64 bit workstation you need to install to Program Files (x86) that is done by default because the $PROGRAMFILES constant goes to the Program Files (x86) directory.
So a simple solution that should be obvious is to check for something that is on a 64 bit machine that is not on a 32 bit machine. Lets make a list of such differences.
- c:\Program Files (x86) – Since this is just a folder, it could exist on a 32 bit machine, though that would be unlikely.
- HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node – This is a 64 bit registry and does not exist in 32 bit operating systems.
So some of these are susceptible to be “faked”. I could see some idiot writing an installer on Windows 7 and hard coding the Program Files (x86) directory so it is installed there even on 32 bit systems. The SysWow64 directory seems more safe and it exists on Vista, Windows 7, and 2008. I don’t have XP or 2003 64 bit machines so someone can check for me. It seems that the registry key is also likely to be a safe check.
You can check any of these you want.
Here is how you would change which registry to work with.
IfFileExists $WINDIR\SYSWOW64\*.* Is64bit Is32bit Is32bit: SetRegView 32 GOTO End32Bitvs64BitCheck Is64bit: SetRegView 64 End32Bitvs64BitCheck:
That fixes the registry keys. So if you only care about the registry you are fine. However, you software will still install to the Program Files (x86) directory. To fix both, you could place the following code in BOTH the .onInit and the un.onInit functions.
; Install to the correct directory on 32 bit or 64 bit machines IfFileExists $WINDIR\SYSWOW64\*.* Is64bit Is32bit Is32bit: MessageBox MB_OK "32 bit" SetRegView 32 StrCpy $INSTDIR "$PROGRAMFILES32\LANDesk\Health Check" GOTO End32Bitvs64BitCheck Is64bit: MessageBox MB_OK "64 bit" SetRegView 64 StrCpy $INSTDIR "$PROGRAMFILES64\LANDesk\Health Check" End32Bitvs64BitCheck:
Don’t forget to comment out the usual place that INSTDIR is configured.
Anyway, that seems to work.
Copyright ® Rhyous.com – Linking to this page is allowed without permission and as many as ten lines of this page can be used along with this link. Any other use of this page is allowed only by permission of Rhyous.com.