Solved

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

Posted on 2011-09-28
4
352 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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