?
Solved

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

Posted on 2011-09-28
4
Medium Priority
?
354 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 1000 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 1000 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

Industry Leaders: 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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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