Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2006

Tip: Looking for answers? Try searching our database.

How to determine bitness of underlying OS from C#?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
StewLG - 24 Apr 2006 23:11 GMT
I have a C# app I'm writing that will be run on both Win32 and Win64
platforms. I'm limited to XP, 2003, Vista and beyond, and don't have to
support 9x/2000/NT.

This application calls other, external tools to do its work, and which
tool should be used varies depending on the platform and whether it is
64 bit or 32 bit.

Things I perceive as dead ends:

IsWow64Process. This seems to be NOT what I want, since I actually
don't care if the C# app is running in 32 bit mode or 64 bit mode --
it's irrelevant to me. What I care about is  "Am I running on a
Win32-only platform, or a Win64 capable platform?"

GetNativeSystemInfo. This tells me what the physical hardware is, but
that doesn't tell me what OS is running on it.

If it comes to that, I'll write a command line tool in C++ that does
nothing but answer this question for me. But I thought I'd make sure
there was no other way before I resorted to this.

Is there a clean way to determine if I'm running on a 64-bit OS from
C#?

I will try to read responses to the group, but email CC's are greatly
appreciated.

Stew
cody - 25 Apr 2006 09:15 GMT
does sizeof(IntPtr) help?

> I have a C# app I'm writing that will be run on both Win32 and Win64
> platforms. I'm limited to XP, 2003, Vista and beyond, and don't have to
[quoted text clipped - 25 lines]
>
> Stew
StewLG - 25 Apr 2006 16:29 GMT
I can't even compile sizeof(IntPtr) in a safe way.

return sizeof(IntPtr);

Gets me this error:

Error    2    'System.IntPtr' does not have a predefined size, therefore
sizeof can only be used in an unsafe context (consider using
System.Runtime.InteropServices.Marshal.SizeOf)
cody - 25 Apr 2006 17:19 GMT
IntPtr has a static property "Size" which will tell you.

>I can't even compile sizeof(IntPtr) in a safe way.
>
[quoted text clipped - 5 lines]
> sizeof can only be used in an unsafe context (consider using
> System.Runtime.InteropServices.Marshal.SizeOf)
StewLG - 19 May 2006 16:03 GMT
Ok, I can now distinguish 32 from 64 bit platforms. This is a good
start

Now, how can I distinguish IA64 from x86-64, from C#?
cody - 19 May 2006 16:56 GMT
Iam afraid you can't with pure .net. use p/invoke for that there are many
libraries out there which detects cpu type and similar hardware
configuration stuff.

> Ok, I can now distinguish 32 from 64 bit platforms. This is a good
> start
>
> Now, how can I distinguish IA64 from x86-64, from C#?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.