Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# LinkButton OnClientClick 2 34
C# application error "Parameter Is Not Valid". 3 79
Syntax Error 2 46
Not showing JavaScript in the list 5 39
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now