Results 1 to 20 of 20

Thread: [RESOLVED] [2005] detect 64bit os

  1. #1

    Thread Starter
    Addicted Member Lectere's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    222

    Resolved [RESOLVED] [2005] detect 64bit os

    LS,

    I would like to know if someone has a easy way to determinte if the OS my program is running on is x64 or 32bit?

    So to be clear, I don't wanna know if my processer supports x64, I wanna know if the windows version is either 64 bits or 32 bits.

    I've tried searching the forums and google, no succes..

    Thanks in advance!

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2005] detect 64bit os

    Would this work?
    vb Code:
    1. Me.Text = My.Computer.Info.OSPlatform.ToString
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3

    Thread Starter
    Addicted Member Lectere's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    222

    Re: [2005] detect 64bit os

    great thanks resolved!

  4. #4
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Re: [RESOLVED] [2005] detect 64bit os

    this doesnt not work... it replies back winNT32 to me, im running vista ultimate 64bit...
    How To Make A Youtube Downloader
    I use Visual Studio 2008 Pro...

  5. #5
    New Member
    Join Date
    Oct 2008
    Posts
    4

    Re: [RESOLVED] [2005] detect 64bit os

    You have to use wmi into your vb code.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    see if My.Computer.Info.OSFullName
    contains the string "x64"

    "x86" = 32 bit
    Last edited by dbasnett; Oct 26th, 2008 at 09:28 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Re: [RESOLVED] [2005] detect 64bit os

    this is how you do it
    vb.net Code:
    1. Dim architecture As Integer = Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr)) * 8
    2.  
    3. if architecture = 32 then
    4.  
    5. ElseIf architecture = 64 Then
    6.  
    7. endif
    How To Make A Youtube Downloader
    I use Visual Studio 2008 Pro...

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    aren't there two versions of wmi, one for 32 and one for 64?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    New Member
    Join Date
    Oct 2008
    Posts
    4

    Re: [RESOLVED] [2005] detect 64bit os

    you can use the 32 bit version. You need only to search the "x64" string into the fields resulting from the following query:

    New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    My.Computer.Info.OSFullName contains x64(64 bit) or x86(32 bit). wmi queries are slow, IMHO.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] detect 64bit os

    What's with the bringing up of ancient threads about this?
    I already wrote today that it is enough to directly check the size of intptr.

    MessageBox.Show(IntPtr.Size.ToString)
    VB 2005, Win Xp Pro sp2

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    i write / compile an application named foo with a 32 bit target platform.

    then i run foo on a 64 bit os.

    what size is intptr when foo runs on a 64 bit machine?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] detect 64bit os

    IntPtr is an integer with a twist. Something like the integer in vb6 and vb .net and later. In 6 an integer is 16 bit, in .net it is 32 bit.

    Quote Originally Posted by MSDN
    The IntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.
    If foo uses an IntPtr, it will be 8 bytes on a 64 bit OS, provided foo manages to start of course.
    VB 2005, Win Xp Pro sp2

  14. #14
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [RESOLVED] [2005] detect 64bit os

    Quote Originally Posted by Half
    What's with the bringing up of ancient threads about this?
    I already wrote today that it is enough to directly check the size of intptr.

    MessageBox.Show(IntPtr.Size.ToString)
    Very clever though I just tried running this code on my Vista 64-bit machine and it returned a 4

    Edit: Actually it appears ASP.Net applications, regardless of what the build options are set to, run in 32-bit mode as this code returns a 4 on my 64-bit system. If I create a new Windows Forms project then this works correctly. Interesting...
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    "The IntPtr type is designed to be an integer whose size is platform-specific." That is what I am asking. Isn't it the target as specified at compile time? Or are you implying the data type changes structure at run-time?

    If foo is targeted at 32 bit os, doesn't it have to run under WOW64 on a 64 bit os, which I think returns 4 as the size of intptr?

    i guess if i had a 64 bit os i'd know the answer.
    Last edited by dbasnett; Oct 26th, 2008 at 01:40 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] detect 64bit os

    If ASP supports only 4 byte IntPtrs, it won't be able to use memory above the 4th gb mark. So either ASP is 32 bit only or there is more to it.

    This supposedly can 'make' ASP 64bit.

    dbasnett's doubts are valid unfortunately. IntPtr.Size is a hard coded property that is conditionally compiled to be either 4 or 8 depending on whether you're in a process that loaded up the 32bit version of mscorlib.dll or the 64bit version.
    VB 2005, Win Xp Pro sp2

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    i guess it is good we brought it up.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [RESOLVED] [2005] detect 64bit os

    Quote Originally Posted by Half
    dbasnett's doubts are valid unfortunately. IntPtr.Size is a hard coded property that is conditionally compiled to be either 4 or 8 depending on whether you're in a process that loaded up the 32bit version of mscorlib.dll or the 64bit version.
    I think your method is still good. Your method will show whether the process is running in a 32-bit or 64-bit mode. This is potentially better than the WMI solution depending on your purposes.

    Let's say you have to interface with a native DLL but there is a 32-bit and a 64-bit version for performance purposes. Using your method would allow you to dynamically choose the correct one no matter what. Even if your application runs on a 64-bit machine but is forced to run in 32-bit mode it will still work perfectly.

    If you're attempting to do the same thing via WMI and your application is really running in 32-bit mode on a 64-bit machine, it's going to crash and burn.

    This is exceptionally useful in a .Net library as it could be used in ASP.Net or Windows Forms applications.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] detect 64bit os

    you all are just trying to make this harder than it is. if My.Computer.Info.OSFullName contains the string "x64" then you are running a 64 bit os, and i am going out on a limb here, it is probably a 64 bit machine. And it will say that even if your app was written for a 32 bit platform.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [RESOLVED] [2005] detect 64bit os

    Quote Originally Posted by dbasnett
    you all are just trying to make this harder than it is. if My.Computer.Info.OSFullName contains the string "x64" then you are running a 64 bit os, and i am going out on a limb here, it is probably a 64 bit machine. And it will say that even if your app was written for a 32 bit platform.
    You already stated this... what was your point and who was making it harder?

    The IntPtr method, as we were discussing, will show if your application is being run in 32-bit or 64-bit mode where as your method will only show if you're running on a 32-bit of 64-bit machine. Not exactly the same thing and while your solution is [probably] the most appropriate for the op, I was just trying to state that the IntPtr method can still be useful.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width