Solved

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

Posted on 2011-09-28
4
347 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# remove trailing commas from csv file 10 44
comparing string in C# 3 31
Image(7) 1 32
Achieve json result 2 20
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

11 Experts available now in Live!

Get 1:1 Help Now