Friday, January 2, 2009

NSIS Script for 64 Bit Machine

Today i was working on the NSIS scripts. In this perticular script i have to write the registry values in the system. There is a function call WriteRegExpandStr.
syntax: WriteRegExpandStr HKLM "Software\ProductName" "dbServer" "anyvalue"
This function will write the registry value "anyvalue" in the registry with the keyname as dbserver. Now this works good when we have the 32 bit machine. Now when you have 64 bit machine and then this value you won't see under "Software\ProductName" . By default it will be created under the "Software\Wow6432Node\ProductName" . In my case my application reading the data from the Software\ProductName and there is no data as the registry values are written under Software\Wow6432Node\ProductName . Just to keep my code in tacke i have write a small function which will check if the machine is 64 bit or a 32 bit. Depend on the machine type it will get and update the data from the registry. Below is the code
public static string CheckIf64BitOS()
{
int bits = IntPtr.Size * 8;
return bits.ToString();
}

if (CheckIf64BitOS().Equals("64")) {//Write a logic for 64 bit}
if (CheckIf64BitOS().Equals("32")) {//Write a logic for 32 bit}

Hope this will solve your problem.

1 comment:

kichik said...

You can also have the installer write it to the correct place by using SetRegView x64. To figure out in the installer if you're running on x64, use the macros from x64.nsh.