My application needs to know if a program is installed on the machine in order to work, and I want the option to know if Program Files folder exist in only the (32 Bit machine) or also has the Program Files (x86) folder (64 Bit machine).
What is the best way to do it via my code?
my application that i need on the machine is Wireshark that can install on both 32 and 64 bit (in the appropriate Program Files folder) and i am not sure what to do because i am making installer file with Wireshark inside and try to find the best option to know what to install.
To dynamically get the correct Program Files (x86) path, use
On 32-bit systems, this will return the regular Program Files directory. On 64-bit systems, this will return the Program Files (x86) directory.
In your specific case, as I understand it, you want to install the 64-bit Wireshark on a 64-bit system, so you want to launch the 64-bit installer, unless it’s already available. If that’s the case, you can ignore the Program Files (x86) entirely, and only check Program Files. If, however, you want to use an existing 32-bit Wireshark if available, you’d need to check each location Wireshark could be installed in: check in ProgramFiles, if not found, check in ProgramFilesX86, if not found, launch installer. The installer to use can be determined based on
Environment.Is64BitOperatingSystem(from Furqan’s answer).