How can I identified if the running OS a 32bit or 64bit version?

  • Thread starter Thread starter McHansy
  • Start date Start date
I see now a solution for this problem
Into the Registrykey
LocalMachine\HARDWARE\DESCRIPTION\System\CentralProcessor\0\Identifier
the 32bit Windows will be write
x86 Family 6 Model 15 Stepping 6
the 64bit Windows will be write
EM64T Family 6 Model 15 Stepping 6

on the same Machine. Now I evaluate the first part of the string and decide
me for the OS.
 
Mark Rae said:
Er, no... This tells you what processor the machine has, not what OS is
installed - it's perfectly possible to install 32-bit Windows on a machine
with a 64-bit processor...

Also, reading the HKLM Registry hive is not recommended on machines running
Vista because of UAC considerations...

I know this is not the bestway but I found no other way. Your solution with
the directories are also not clear. I test my solution on the same machine
(with the same processor (Intel Core 2 CPU 6320)) and it works with
WinXP(32bit), WinXP(64bit), Vista(32bit) and Vista(64bit). I have no
Problems with the UAC.
 
Mark Rae said:
if (Directory.Exists(Environment.GetEnvironmentVariable("SystemDrive") +
"\\Program Files (x86)"))
{
// 64-bit Windows
}

Which part of the above code is not clear...?



The machine on which I'm writing this post has a 64-bit processor and is
running 64-bit Windows. The Registry entry for the key that you are using
says "Intel64 Family 6 Model 15 Stepping 6" - no mention of of EM64T. You
have absolutely no guarantee that a 32-bit OS will always show an Identifier
value beginning "x86"...

I found a MSDN entry http://support.microsoft.com/kb/556009/en-us and this
report the same way than me.
Of course you don't. You're a developer, so you're running Visual Studio.NET
with elevated permissions, your account is local admin on your machine etc.
This may not be the case for your users...
http://www.vistaheads.com/forums/mi...gistry-keys-under-hklm-uac-enabled-vista.html
http://www.eggheadcafe.com/community/aspnet/2/10042159/registry-permission-class.aspx

On the Test workstation is no Visual Studio running.
 
Can you use Marshal.SizeOf(typeof(IntPtr)) ? I know on my 64bit OS
that reports 8. I'm just not sure that a 32bit OS would report 4,
although I would think that it would.
 
You can, but not to determine whether the underlying OS is 32-bit or
64-bit...


That has nothing whatsoever to do with your OS.

In Project Explorer, right-click on your project, click Properties, select
the Build tab and change the Platform target dropdown to "x86" - now what
does the above code give...?

How about calling IsWow64Process?
If GetProcAddress fails, it's 32-bit, otherwise it's 64-bit if
IsWow64Process
gives a true.
 
Mark said:
This is incorrect, for the same reason as the previous suggestion.

Specifically, this will tell you whether the current *process* is
32-bit or 64-bit, not whether the underlying operating system is
32-bit or 64-bit:
http://social.msdn.microsoft.com/Fo.../thread/24792cdc-2d8e-454b-9c68-31a19892ca53/

But the tests taken together do tell you.

if sizeof( IntPtr ) == 8 then 64-bit app, 64-bit OS
else if GetProcAddress("IsWow64Process") == NULL then 32-bit app, old 32-bit
OS
else if IsWow64Process() then 32-bit app, 64-bit OS
else 32-bit app, new 32-bit OS
 
Back
Top