Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Determine executing OS, not application architecture

Determine executing OS, not application architecture

Scheduled Pinned Locked Moved .NET (Core and Framework)
testingbeta-testingarchitecturetutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tony Teveris
    wrote on last edited by
    #1

    I'm not sure why this has to be so hard but I've check and seen a bunch of solutions that do not work. Currently I've tried this: Private Structure SYSTEM_INFO Public wProcessorArchitecture As Integer Public wReserved As Integer Public dwPageSize As Long Public lpMinimumApplicationAddress As Long Public lpMaximumApplicationAddress As Long Public dwActiveProcessorMask As Long Public dwNumberOfProcessors As Long Public dwProcessorType As Long Public dwAllocationGranularity As Long Public wProcessorLevel As Integer Public wProcessorRevision As Integer End Structure Private Declare Sub GetNativeSystemInfo Lib "kernel32" (ByVal lpSystemInfo As SYSTEM_INFO) . . . Dim si As SYSTEM_INFO GetNativeSystemInfo(si) If si.wProcessorArchitecture = 9 Then Console.WriteLine("64 bitter") End If . . . What I noticed is that the structure never gets filled in. I'm testing this on a Windows 7 64 bit OS Any idea why this does not work or any ideas on how to figure out the OS architecture? Thanks in advance

    Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

    S L 2 Replies Last reply
    0
    • T Tony Teveris

      I'm not sure why this has to be so hard but I've check and seen a bunch of solutions that do not work. Currently I've tried this: Private Structure SYSTEM_INFO Public wProcessorArchitecture As Integer Public wReserved As Integer Public dwPageSize As Long Public lpMinimumApplicationAddress As Long Public lpMaximumApplicationAddress As Long Public dwActiveProcessorMask As Long Public dwNumberOfProcessors As Long Public dwProcessorType As Long Public dwAllocationGranularity As Long Public wProcessorLevel As Integer Public wProcessorRevision As Integer End Structure Private Declare Sub GetNativeSystemInfo Lib "kernel32" (ByVal lpSystemInfo As SYSTEM_INFO) . . . Dim si As SYSTEM_INFO GetNativeSystemInfo(si) If si.wProcessorArchitecture = 9 Then Console.WriteLine("64 bitter") End If . . . What I noticed is that the structure never gets filled in. I'm testing this on a Windows 7 64 bit OS Any idea why this does not work or any ideas on how to figure out the OS architecture? Thanks in advance

      Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

      S Offline
      S Offline
      Sir Dot Net
      wrote on last edited by
      #2

      Look at Environment.OSVersion

      T 1 Reply Last reply
      0
      • T Tony Teveris

        I'm not sure why this has to be so hard but I've check and seen a bunch of solutions that do not work. Currently I've tried this: Private Structure SYSTEM_INFO Public wProcessorArchitecture As Integer Public wReserved As Integer Public dwPageSize As Long Public lpMinimumApplicationAddress As Long Public lpMaximumApplicationAddress As Long Public dwActiveProcessorMask As Long Public dwNumberOfProcessors As Long Public dwProcessorType As Long Public dwAllocationGranularity As Long Public wProcessorLevel As Integer Public wProcessorRevision As Integer End Structure Private Declare Sub GetNativeSystemInfo Lib "kernel32" (ByVal lpSystemInfo As SYSTEM_INFO) . . . Dim si As SYSTEM_INFO GetNativeSystemInfo(si) If si.wProcessorArchitecture = 9 Then Console.WriteLine("64 bitter") End If . . . What I noticed is that the structure never gets filled in. I'm testing this on a Windows 7 64 bit OS Any idea why this does not work or any ideas on how to figure out the OS architecture? Thanks in advance

        Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Environment.OSVersion is good enough for me. your "ByVal" is obviously wrong, where is the output going to go? :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        T 1 Reply Last reply
        0
        • S Sir Dot Net

          Look at Environment.OSVersion

          T Offline
          T Offline
          Tony Teveris
          wrote on last edited by
          #4

          On my Windows 7 64 bit the value is "Microsoft Windows NT 6.1.7600.0"

          Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

          S 1 Reply Last reply
          0
          • L Luc Pattyn

            Environment.OSVersion is good enough for me. your "ByVal" is obviously wrong, where is the output going to go? :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            T Offline
            T Offline
            Tony Teveris
            wrote on last edited by
            #5

            Right now I'm just debugging the code and just looking "quick watch" on the structure. As a first time .Net/VB coder it should be ByRef. Now it works. I'll do more testing on other OSs

            Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

            1 Reply Last reply
            0
            • T Tony Teveris

              On my Windows 7 64 bit the value is "Microsoft Windows NT 6.1.7600.0"

              Tony Teveris Gerber Scientific Products Senior Software Engineer Phone: 860 648 8151 Fax: 860 648 8214 83 Gerber Road West South Windsor, CT 06074

              S Offline
              S Offline
              Sir Dot Net
              wrote on last edited by
              #6

              if(IntPtr.Size == 8) { //64-bit } else if(IntPtr.Size == 4) { //32-bit } This is based off the OS installed, not the CPU which is what I think you are looking for.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups