-1

i have an application whose path should be in registry to run, the problem is that i have to use this application for both 32 bit and 64 bit machines and i need common registry setting that should work on both 32 bit and 64 bit machines.

i have also used environment variables but it did not solve my issue like,

"%programfiles%\ABC\abc.exe"

2 Answers2

1

If the expandable registry key did not work, you could always try to do the expanding yourself like this for example:

        string strRegistryKeyValue = "%programfiles%/ABC/abc.exe";
        string strProgramFiles;
        if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
        {
            strProgramFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
        }
        else
        {
            strProgramFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
        }
        strRegistryKeyValue = strRegistryKeyValue.Replace("%programfiles%", strProgramFiles);
Fixation
  • 969
  • 6
  • 12
0

When you put the executable on the machine, presumably with your installer, you know where you put it. You will have had to find out the path to the program files folder in order to copy the file. At that point, the location is fixed. The machine is either 32 bit or 64 bit. It cannot change. So, you know the path to the executable, and you simply write that path to the registry.

Typically you will be doing all this from your installer program. And it will know where the file was installed. It will provide functionality to write this registry key using the actual location of the file that it is installing.

There is no need at all for any more indirection at this point. By the time you have got as far as writing a file to the machine, you have chosen a location for it. That choice is then static. If the file went in Program Files (x86) then that's where it is. If it went in Program Files, again there it is. You simply don't need to encode the indirection into the registry because the indirection has been expanded at this point.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Actually this application is to be installed by the NTAdmin, and i need to add this key manually by applying group policy. So i can not fix this using code. – Muhammad Babar Nazir Jun 19 '14 at 16:09
  • 1
    I gave an answer to match the level of detail in the question. If you wanted specifics then you would have asked a specific question with details of your installation environment. Since you did not, this is therefore a conceptual question. If your question is about group policy and sysadmin then this is the wrong place to ask. Remember that stack overflow is for programming questions. It sounds as though you should ask at http://serverfault.com – David Heffernan Jun 19 '14 at 16:11