473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Underlying OS architecture

Hello,

There was a thread recently about how to tell if the installed version of
Windows is 32-bit or 64-bit, but that seems to have disappeared from my
newsreader so apologies for starting a new thread.

Anyway, the first suggestion was to use IntPtr.Size. That is clearly wrong,
because that will only tell you if your *application* is 32-bit or 64-bit
e.g.

32-bit app on 32-bit OS - IntPtr.Size = 4
64-bit app on 64-bit OS - IntPtr.Size = 8
32-bit app on 64-bit OS - IntPtr.Size = 4

so that's no use, and similar API calls also seem to be unreliable for the
same reason.

The second suggestion was to use WMI, specifically the OSArchitecture value
of the Win32_OperatingSystem class in the System.Management namespace. The
problem with that is that it is available only in Vista -
http://msdn2.microsoft.com/En-US/library/aa394239.aspx which makes it almost
worse than useless.

[There was also a comment that nobody really needs to know this information
anyway, which may be true, but doesn't provide a solution.]

The only way that I can find to do this is:

1) find the drive letter that Windows is installed on (from WMI)

2) add ":\\Program Files (x86)" to it

3) see if the resulting folder exists with Directory.Exists

This is fairly obviously pretty awful but is the most reliable method I have
found so far.

Can anyone suggest a better way?

Thanks,

DJ
Jun 19 '07 #1
13 4962
David,

I am curious, what is it that you are trying to do exactly? Why do you
need to know whether the OS is 64 bit as opposed to the mode under which
your app is running?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Jackson" <so*****@somewhere.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Hello,

There was a thread recently about how to tell if the installed version of
Windows is 32-bit or 64-bit, but that seems to have disappeared from my
newsreader so apologies for starting a new thread.

Anyway, the first suggestion was to use IntPtr.Size. That is clearly
wrong, because that will only tell you if your *application* is 32-bit or
64-bit e.g.

32-bit app on 32-bit OS - IntPtr.Size = 4
64-bit app on 64-bit OS - IntPtr.Size = 8
32-bit app on 64-bit OS - IntPtr.Size = 4

so that's no use, and similar API calls also seem to be unreliable for the
same reason.

The second suggestion was to use WMI, specifically the OSArchitecture
value of the Win32_OperatingSystem class in the System.Management
namespace. The problem with that is that it is available only in Vista -
http://msdn2.microsoft.com/En-US/library/aa394239.aspx which makes it
almost worse than useless.

[There was also a comment that nobody really needs to know this
information anyway, which may be true, but doesn't provide a solution.]

The only way that I can find to do this is:

1) find the drive letter that Windows is installed on (from WMI)

2) add ":\\Program Files (x86)" to it

3) see if the resulting folder exists with Directory.Exists

This is fairly obviously pretty awful but is the most reliable method I
have found so far.

Can anyone suggest a better way?

Thanks,

DJ

Jun 19 '07 #2
On Jun 19, 4:41 pm, "David Jackson" <some...@somewhere.comwrote:
The only way that I can find to do this is:

1) find the drive letter that Windows is installed on (from WMI)

2) add ":\\Program Files (x86)" to it

3) see if the resulting folder exists with Directory.Exists

This is fairly obviously pretty awful but is the most reliable method I have
found so far.
Unfortunately I don't have a solution for you, but I just wanted to
note that this would fail on non-English builds of Windows.
Matt

Jun 19 '07 #3
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:On****************@TK2MSFTNGP02.phx.gbl...
I am curious, what is it that you are trying to do exactly?
Find out whether my app is running on 32-bit or 64-bit Windows.
Why do you need to know whether the OS is 64 bit
Does that actually matter...? Does that prevent you from helping me...?
Jun 19 '07 #4
<kt*******@sneakemail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...

Matt,

Thanks very much for the reply.
Unfortunately I don't have a solution for you,
I'm beginning to think there may not be one!
but I just wanted to note that this would fail on non-English
builds of Windows.
Yes it would. As I mentioned, it's a totally awful suggestion, but I have
nothing better at the moment.

DJ
Jun 19 '07 #5
David,

As for whether or not it could matter, yes, it could (and not because of
personal reasons). More information about a problem ALWAYS helps, and by
having a greater understanding of what is going on in general, it could lead
to a different, but equally effective solution which is more appropriate for
what you are trying to do.

But without that information, it prevents myself, as well as a lot of
other people here from having a greater understanding of your problem, which
will prevent them from possibly providing a solution to your problem.

The next time you want to ask if the information will prevent people
from helping you, remember that when they ask, they are already trying to
help you by asking. They are already taking time to have a greater
understanding of YOUR problem. There is no need to ask them again. Rather,
enable the people that are trying to help you by giving them what they are
asking for, and I can guarantee that you will always get a better response
in terms of the quality of the answer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Jackson" <so*****@somewhere.comwrote in message
news:ux**************@TK2MSFTNGP05.phx.gbl...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:On****************@TK2MSFTNGP02.phx.gbl...
>I am curious, what is it that you are trying to do exactly?

Find out whether my app is running on 32-bit or 64-bit Windows.
>Why do you need to know whether the OS is 64 bit

Does that actually matter...? Does that prevent you from helping me...?

Jun 19 '07 #6
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:un**************@TK2MSFTNGP04.phx.gbl...

Nicholas,

I apologize profusely if I have offended you. I had no intention to do that.

Fact is, I have no reason whatever for wanting to know how to do this other
than for my own interest and to increase my own knowledge.

It just seems to me a perfectly reasonable and straightforward thing to want
to know how to do!

Microsoft have provided a mechanism for it in WMI (even though that only
works in Vista), so somebody somewhere must have asked for it at some point
:-)

DJ
Jun 19 '07 #7
There are probably a few ways to find this out. The first one to pop into my
head would be to check the pointer size. If it is 8 then the OS is 64-bit.
If it is 4 then the OS may be 32-bit or 64-bit, just call IsWow64Process to
find out which.
"David Jackson" <so*****@somewhere.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Hello,

There was a thread recently about how to tell if the installed version of
Windows is 32-bit or 64-bit, but that seems to have disappeared from my
newsreader so apologies for starting a new thread.

Anyway, the first suggestion was to use IntPtr.Size. That is clearly
wrong, because that will only tell you if your *application* is 32-bit or
64-bit e.g.

32-bit app on 32-bit OS - IntPtr.Size = 4
64-bit app on 64-bit OS - IntPtr.Size = 8
32-bit app on 64-bit OS - IntPtr.Size = 4

so that's no use, and similar API calls also seem to be unreliable for the
same reason.

The second suggestion was to use WMI, specifically the OSArchitecture
value of the Win32_OperatingSystem class in the System.Management
namespace. The problem with that is that it is available only in Vista -
http://msdn2.microsoft.com/En-US/library/aa394239.aspx which makes it
almost worse than useless.

[There was also a comment that nobody really needs to know this
information anyway, which may be true, but doesn't provide a solution.]

The only way that I can find to do this is:

1) find the drive letter that Windows is installed on (from WMI)

2) add ":\\Program Files (x86)" to it

3) see if the resulting folder exists with Directory.Exists

This is fairly obviously pretty awful but is the most reliable method I
have found so far.

Can anyone suggest a better way?

Thanks,

DJ

Jun 19 '07 #8
"David Jackson" <so*****@somewhere.comwrote in message
news:uC**************@TK2MSFTNGP02.phx.gbl...
Hello,

There was a thread recently about how to tell if the installed version of
Windows is 32-bit or 64-bit, but that seems to have disappeared from my
newsreader so apologies for starting a new thread.

Anyway, the first suggestion was to use IntPtr.Size. That is clearly
wrong, because that will only tell you if your *application* is 32-bit or
64-bit e.g.

32-bit app on 32-bit OS - IntPtr.Size = 4
64-bit app on 64-bit OS - IntPtr.Size = 8
32-bit app on 64-bit OS - IntPtr.Size = 4

so that's no use, and similar API calls also seem to be unreliable for the
same reason.

The second suggestion was to use WMI, specifically the OSArchitecture
value of the Win32_OperatingSystem class in the System.Management
namespace. The problem with that is that it is available only in Vista -
http://msdn2.microsoft.com/En-US/library/aa394239.aspx which makes it
almost worse than useless.

[There was also a comment that nobody really needs to know this
information anyway, which may be true, but doesn't provide a solution.]

The only way that I can find to do this is:

1) find the drive letter that Windows is installed on (from WMI)

2) add ":\\Program Files (x86)" to it

3) see if the resulting folder exists with Directory.Exists

This is fairly obviously pretty awful but is the most reliable method I
have found so far.

Can anyone suggest a better way?

Thanks,

DJ

In your code, you first need to check the size of IntPtr, if it returns 8
then you are running on a 64-bit OS.
If it returns 4, you are running a 32 bit application, so now you need to
know whether you are running natively or under WOW64.
To get this information you will need to call kernel32.dll API
"IsWow64Process" using PInvoke, this API returns a Boolean 'true' if you are
running under WOW64, that means you are running 32 bit application on a
64-bit Windows system.
Be careful however to check the OS version before calling this API, only XP
SP2 and implements this one.

Willy.

Jun 19 '07 #9
David,

You can get this without WMI. Check out the section of the MSDN
documentation titled "Running 32-bit Applications", located at:

http://msdn.microsoft.com/library/de...plications.asp

You will have to call the API through the P/Invoke layer. You will also
have to call GetProcAddress to see if the IsWow64Process API is exposed.
From what I can tell, if it is not exposed, then you are running on a 32 bit
system, if it is, then you are running on a 64 bit system.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Jackson" <so*****@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:un**************@TK2MSFTNGP04.phx.gbl...

Nicholas,

I apologize profusely if I have offended you. I had no intention to do
that.

Fact is, I have no reason whatever for wanting to know how to do this
other than for my own interest and to increase my own knowledge.

It just seems to me a perfectly reasonable and straightforward thing to
want to know how to do!

Microsoft have provided a mechanism for it in WMI (even though that only
works in Vista), so somebody somewhere must have asked for it at some
point :-)

DJ

Jun 19 '07 #10
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...

Hi Willy,

Thanks for the reply.
In your code, you first need to check the size of IntPtr, if it returns 8
then you are running on a 64-bit OS.
If it returns 4, you are running a 32 bit application, so now you need to
know whether you are running natively or under WOW64.
To get this information you will need to call kernel32.dll API
"IsWow64Process" using PInvoke, this API returns a Boolean 'true' if you
are running under WOW64, that means you are running 32 bit application on
a 64-bit Windows system.
Be careful however to check the OS version before calling this API, only
XP SP2 and implements this one.
OK, so if I've understood correctly...

If IntPtr.Size is 8, it must be 64-bit Windows - if it's 4, it could be
32-bit or 64-bit.

If it's 4, we firstly need to check if we're running Vista or XP.

If it's Vista, we use OSArchitecture from WMI

If it's XP, and only then if it's SP2, we use the IsWow64Process API call

If it's not XP+SP2, we have no means of knowing.

Is that correct?

DJ
Jun 19 '07 #11
"David Jackson" <so*****@somewhere.comwrote in message
news:Oi**************@TK2MSFTNGP06.phx.gbl...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...

Hi Willy,

Thanks for the reply.
>In your code, you first need to check the size of IntPtr, if it returns 8
then you are running on a 64-bit OS.
If it returns 4, you are running a 32 bit application, so now you need to
know whether you are running natively or under WOW64.
To get this information you will need to call kernel32.dll API
"IsWow64Process" using PInvoke, this API returns a Boolean 'true' if you
are running under WOW64, that means you are running 32 bit application on
a 64-bit Windows system.
Be careful however to check the OS version before calling this API, only
XP SP2 and implements this one.

OK, so if I've understood correctly...

If IntPtr.Size is 8, it must be 64-bit Windows - if it's 4, it could be
32-bit or 64-bit.
Right. Pointers are 8 bytes long on a 64-bit OS.
If it's 4, we firstly need to check if we're running Vista or XP.
Right, check the OperatingSystem.Version and OperatingSystem.ServicePack
properties.
If it's Vista, we use OSArchitecture from WMI
Not necessarely, I would currently opt for a single API solution:
IsWow64Process.
If it's XP, and only then if it's SP2, we use the IsWow64Process API call
No, when it is XP SP2 or higher!. On XP SP2, Windows 2003, Vista, Windows
2008, and .... you can use the IsWow64Process API.
If it's not XP+SP2, we have no means of knowing.
If it's not XP2 or higher, It can't be an 64--bit OS.

Willy.

Jun 19 '07 #12
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:ua**************@TK2MSFTNGP02.phx.gbl...

Hi Willy,
>If it's Vista, we use OSArchitecture from WMI
Not necessarely, I would currently opt for a single API solution:
IsWow64Process.
OK - I was obviously taking your previous statement too literally: "Be
careful however to check the OS version before calling this API, only XP SP2
implements this one."
No, when it is XP SP2 or higher!. On XP SP2, Windows 2003, Vista, Windows
2008, and .... you can use the IsWow64Process API.
Understood now.
>If it's not XP+SP2, we have no means of knowing.

If it's not XP2 or higher, It can't be an 64--bit OS.
Oh right. So 64-bit XP was released already at SP2? I wasn't aware of
that...

In which case I think we have a solution!

Thanks for all you help.

DJ
Jun 19 '07 #13
"David Jackson" <so*****@somewhere.comwrote in message
news:eB**************@TK2MSFTNGP04.phx.gbl...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:ua**************@TK2MSFTNGP02.phx.gbl...

Hi Willy,
>>If it's Vista, we use OSArchitecture from WMI
Not necessarely, I would currently opt for a single API solution:
IsWow64Process.

OK - I was obviously taking your previous statement too literally: "Be
careful however to check the OS version before calling this API, only XP
SP2 implements this one."
My bad, sorry for the confusion.
>No, when it is XP SP2 or higher!. On XP SP2, Windows 2003, Vista,
Windows 2008, and .... you can use the IsWow64Process API.

Understood now.
>>If it's not XP+SP2, we have no means of knowing.

If it's not XP2 or higher, It can't be an 64--bit OS.

Oh right. So 64-bit XP was released already at SP2? I wasn't aware of
that...
Not really, it's a different code base really, but XP64 is guranteed to have
the API IsWow64Process ;-)
In which case I think we have a solution!

Thanks for all you help.
You're welcome.

Willy.
Jun 19 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: David Noble | last post by:
We've been developing a web site using 3-tier architecture for 18 months now. There is a common layer that defines the classes - using XML schemas. The data layer acts as a wrapper to 3 databases...
4
by: stacdab | last post by:
We have a partitioned view with 4 underlying tables. The view and each of the underlying tables are in seperate databases on the same server. Inserts and deletes on the view work fine. We then...
4
by: apngss | last post by:
what's the differences between collocated architecture and distributed architecture?? My understanding is that collocated architecture has everything in a single machine? i.e. There is only 1...
4
by: Harris | last post by:
Does anyone know how to get the underlying type of an Array type? Here's a bit of code demonstrating what I'm looking for... public Type getUnderlyingType( Type arrayType ) { if(...
6
by: Gary James | last post by:
This may not be a direct C# question, but since I'll be using using C# for development, I thought I'd pose the question here. I'll soon be involved in the design of a new software product that...
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
6
by: carsonbj | last post by:
I have an issue where the below operation works on a little-endian architecture but not on a big-endian architecture. I was under the impression that pointer arithmetic is architecture independant...
13
by: rrs.matrix | last post by:
hi i have to detect the type of CPU. whether it is 32-bit or 64-bit.. how can this be done.. can anyone please help me.. thanks.
0
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . ...
4
by: =?Utf-8?B?QXJuYXVkIFZpc2N1c2k=?= | last post by:
Hi all, we meet a problem since we use WCF to consume java WebServices. Often the first call works then the second raises the following error : "The underlying connection was closed : " We...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.