<p>Since the WMI class Win32_OperatingSystem only includes OSArchitecture in Windows Vista, I quickly wrote up a method using the registry to try and determine whether or not the current system is a 32 or 64bit system.</p>

<pre><code>private Boolean is64BitOperatingSystem()
{
    RegistryKey localEnvironment = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment");
    String processorArchitecture = (String) localEnvironment.GetValue("PROCESSOR_ARCHITECTURE");

    if (processorArchitecture.Equals("x86")) {
        return false;
    }
    else {
        return true;
    }
}
</code></pre>

<p>It's worked out pretty well for us so far, but I'm not sure how much I like looking through the registry. Is this a pretty standard practice or is there a better method?</p>

<p><strong>Edit</strong>: Wow, that code looks a lot prettier in the preview. I'll consider linking to a pastebin or something, next time.</p>

[{'answer_id': 3909, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 1, 'selected': False, 'text': '<p>Looking into the registry is perfectly valid, so long as you can be sure that the user of the application will always have access to what you need.</p>\n'}, {'answer_id': 3911, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 4, 'selected': True, 'text': '<p>Take a look at Raymond Chens solution:</p>\n\n<p><a href="http://blogs.msdn.com/oldnewthing/archive/2005/02/01/364563.aspx" rel="nofollow noreferrer">How to detect programmatically whether you are running on 64-bit Windows</a></p>\n\n<p>and here\'s the PINVOKE for .NET:</p>\n\n<p><a href="http://www.pinvoke.net/default.aspx/kernel32/IsWow64Process.html?diff=y" rel="nofollow noreferrer">IsWow64Process (kernel32)</a></p>\n\n<p><strong>Update:</strong> I\'d take issue with checking for \'x86\'. Who\'s to say what intel\'s or AMD\'s next 32 bit processor may be designated as. The probability is low but it is a risk. You should ask the OS to determine this via the correct API\'s, not by querying what could be a OS version/platform specific value that may be considered opaque to the outside world. Ask yourself the questions, 1 - is the registry entry concerned properly documented by MS, 2 - If it is do they provide a definitive list of possible values that is guaranteed to permit you as a developer to make the informed decision between whether you are running 32 bit or 64 bit. If the answer is no, then call the API\'s, yeah it\'s a but more long winded but it is documented and definitive. </p>\n'}, {'answer_id': 3919, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 1, 'selected': False, 'text': '<p>The easiest way to test for 64-bit under .NET is to check the value of IntPtr.Size.</p>\n\n<p>EDIT: Doh!  This will tell you whether or not the current process is 64-bit, not the OS as a whole.  Sorry!</p>\n'}, {'answer_id': 3922, 'author': 'Jeremy Privett', 'author_id': 560, 'author_profile': 'https://Stackoverflow.com/users/560', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>The easiest way to test for 64-bit under .NET is to check the value of IntPtr.Size.</p>\n</blockquote>\n\n<p>I believe the value of IntPtr.Size is 4 for a 32bit app that's running under WOW, isn't it?</p>\n\n<p><strong>Edit</strong>: @Edit: Yeah. :)</p>\n"}]
['https://Stackoverflow.com/questions/3903', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/560/']