Solved

How to determine programmatically if I'm running on a 64-bit operating system?

Posted on 2011-09-28
4
351 Views
Last Modified: 2012-05-12
Using System.Management objects, how do I determine programmatically if I'm running under a Windows 7 64-bit machine ?
0
Comment
Question by:rmmarsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 250 total points
ID: 36718224
Please try the following:

if (Environment.OSVersion.VersionString.Contains("Windows 7") && Environment.Is64BitOperatingSystem)
{
    // Windows 7, 64-bit
}

Open in new window


System.Environment.OSVersion
http://msdn.microsoft.com/en-us/library/system.environment.osversion.aspx

System.Environment.Is64BitOperatingSystem
http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem.aspx

System.Environment.Is64BitProcess
http://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess.aspx
0
 

Author Comment

by:rmmarsh
ID: 36718277
That seems logical... what I need to know is if a 32-bit program (Firebird) is installed in Program Files or Program Files (x86), without coding a whole bunch of statements.  Is this the best way to accomplish that?
0
 
LVL 4

Accepted Solution

by:
theHollow earned 250 total points
ID: 36719600
Hello
I would check this by looking in the registry.
In order to do that, you will have to know the know the exact application name (display name), like it whows in "Add/Remove Programs" (or "Programs and Features").

Here is a very basic and simple code example for locating the application "Spotify" (which I happen to have installed on my computer):

RegistryKey regKey = null;
String keyPath = null;
String appName = null;
String appPath = null;

appName = "Spotify";
keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\" + appName;
regKey = Registry.LocalMachine.OpenSubKey(keyPath);

if (keyPath != null)
    appPath = regKey.GetValue("InstallLocation") as String;     // Cast to String in case of NULL value

Open in new window

You will now have the install location for the application.
In this example, this is "C:\Program Files (x86)\Spotify"

From this, you will be able to check this with the environment variable for "Program Files".
Environment.SpecialFolder.ProgramFiles. Many ways to go from here.

There is also more information to get (like DisplayName, DisplayVersion, URLInfoAbout, URLUpdateInfo, HelpLink, Publisher,  Comments)

Hope it helped :-)
0
 

Author Closing Comment

by:rmmarsh
ID: 36720083
Thanks to both of you for your time... the response from wdosanjos will help me in other areas, and the response from theHollow gave me exactly what I needed to solve this problem.

Thanks again...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question