Windows Vista Forums

Determine 32 bit or 64 bit of an OS

  1. #1


    IT Staff Guest

    Determine 32 bit or 64 bit of an OS

    Can powershell v2 do that ?



      My System SpecsSystem Spec

  2.   


  3. #2


    Charlie Russel - MVP Guest

    Re: Determine 32 bit or 64 bit of an OS

    $ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if 64-bit.

    --
    Charlie.
    http://msmvps.com/blogs/russel




    "Joe Morris" <j.c.morris@newsgroup> wrote in message
    news:hie55a0co2@newsgroup

    > "IT Staff" <jkklim@newsgroup> wrote:
    >

    >> Can powershell v2 do that ?
    >
    > I was going to answer "of course" since I expected the 'platform' property
    > of the osversion object to provide that information. Checking that just
    > to be sure sadly yields the answer that it doesn't:
    >
    > $os = [environment]:sversion
    > $os.platform
    >
    > ...yields "Win32NT" for both 32- and 64-bit platforms, at least for
    > Windows 7. Sigh...
    >
    > Although some Microsoft documentation claims that build numbers can be
    > used to diffrentiate between different platform versions, that's not
    > correct (Windows 7 and Server 2008 R2 both report build 7600 for both
    > address space values. (Server and client are distinguished by
    > HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareType = "System"
    > or "Server".)
    >
    >
    > There's probably a native POSH test for it somewhere, but a quick check
    > (and one that's self-documenting) is to look at the environment variable
    > Processor_Architecture. Its value will be "x86" for 32-bit and "AMD64"
    > for 64-bit (not necessarily with an AMD chip). There's a third
    > possibility ("IA64") if the Itanium flavor is being used.
    >
    > Or as a practical matter, with a fractionally lower assurance of a correct
    > answer, test for the existence of the folder "C:\Program Files (X86)" as a
    > test for the 64-bit platform.
    >
    > Or you could interrogate any of the several 64-bit-related Registry
    > settings in HKLM\Software\Microsoft\Windows\CurrentVersion or ...\Windows
    > NT\CurrentVersion. Look at these two keys on a 64-bit system and you'll
    > see the entries which tell you that you're running a 64-bit version.
    >
    > Joe Morris
    >

      My System SpecsSystem Spec

  4. #3


    Karl Mitschke Guest

    Re: Determine 32 bit or 64 bit of an OS

    Hello Charlie Russel - MVP,

    > $ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if
    > 64-bit.
    >
    > "Joe Morris" <j.c.morris@newsgroup> wrote in message
    > news:hie55a0co2@newsgroup
    >

    >> "IT Staff" <jkklim@newsgroup> wrote:
    >>

    >>> Can powershell v2 do that ?
    >>>
    >> I was going to answer "of course" since I expected the 'platform'
    >> property of the osversion object to provide that information.
    >> Checking that just to be sure sadly yields the answer that it
    >> doesn't:
    >>
    >> $os = [environment]:sversion
    >> $os.platform
    >> ...yields "Win32NT" for both 32- and 64-bit platforms, at least for
    >> Windows 7. Sigh...
    >>
    >> Although some Microsoft documentation claims that build numbers can
    >> be used to diffrentiate between different platform versions, that's
    >> not correct (Windows 7 and Server 2008 R2 both report build 7600 for
    >> both address space values. (Server and client are distinguished by
    >> HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareType =
    >> "System" or "Server".)
    >>
    >> There's probably a native POSH test for it somewhere, but a quick
    >> check (and one that's self-documenting) is to look at the environment
    >> variable Processor_Architecture. Its value will be "x86" for 32-bit
    >> and "AMD64" for 64-bit (not necessarily with an AMD chip). There's a
    >> third possibility ("IA64") if the Itanium flavor is being used.
    >>
    >> Or as a practical matter, with a fractionally lower assurance of a
    >> correct answer, test for the existence of the folder "C:\Program
    >> Files (X86)" as a test for the 64-bit platform.
    >>
    >> Or you could interrogate any of the several 64-bit-related Registry
    >> settings in HKLM\Software\Microsoft\Windows\CurrentVersion or
    >> ...\Windows NT\CurrentVersion. Look at these two keys on a 64-bit
    >> system and you'll see the entries which tell you that you're running
    >> a 64-bit version.
    >>
    >> Joe Morris
    >>
    Charlie;

    Will that work if a 32 bit OS os installed on top of an x64 processor?

    Karl
    http://unlockpowershell.wordpress.com/



      My System SpecsSystem Spec

  5. #4


    Charlie Russel - MVP Guest

    Re: Determine 32 bit or 64 bit of an OS

    Yes. It reports x86 for a 32-bit OS on 64-bit hardware.

    --
    Charlie.
    http://msmvps.com/blogs/russel




    "Karl Mitschke" <karlmitschke@newsgroup> wrote in message
    news:d66cd4c21a4e68cc60b2178fff3d@newsgroup

    > Hello Charlie Russel - MVP,
    >

    >> $ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if
    >> 64-bit.
    >>
    >> "Joe Morris" <j.c.morris@newsgroup> wrote in message
    >> news:hie55a0co2@newsgroup
    >>

    >>> "IT Staff" <jkklim@newsgroup> wrote:
    >>>
    >>>> Can powershell v2 do that ?
    >>>>
    >>> I was going to answer "of course" since I expected the 'platform'
    >>> property of the osversion object to provide that information.
    >>> Checking that just to be sure sadly yields the answer that it
    >>> doesn't:
    >>>
    >>> $os = [environment]:sversion
    >>> $os.platform
    >>> ...yields "Win32NT" for both 32- and 64-bit platforms, at least for
    >>> Windows 7. Sigh...
    >>>
    >>> Although some Microsoft documentation claims that build numbers can
    >>> be used to diffrentiate between different platform versions, that's
    >>> not correct (Windows 7 and Server 2008 R2 both report build 7600 for
    >>> both address space values. (Server and client are distinguished by
    >>> HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareType =
    >>> "System" or "Server".)
    >>>
    >>> There's probably a native POSH test for it somewhere, but a quick
    >>> check (and one that's self-documenting) is to look at the environment
    >>> variable Processor_Architecture. Its value will be "x86" for 32-bit
    >>> and "AMD64" for 64-bit (not necessarily with an AMD chip). There's a
    >>> third possibility ("IA64") if the Itanium flavor is being used.
    >>>
    >>> Or as a practical matter, with a fractionally lower assurance of a
    >>> correct answer, test for the existence of the folder "C:\Program
    >>> Files (X86)" as a test for the 64-bit platform.
    >>>
    >>> Or you could interrogate any of the several 64-bit-related Registry
    >>> settings in HKLM\Software\Microsoft\Windows\CurrentVersion or
    >>> ...\Windows NT\CurrentVersion. Look at these two keys on a 64-bit
    >>> system and you'll see the entries which tell you that you're running
    >>> a 64-bit version.
    >>>
    >>> Joe Morris
    >>>
    >
    > Charlie;
    >
    > Will that work if a 32 bit OS os installed on top of an x64 processor?
    >
    > Karl
    > http://unlockpowershell.wordpress.com/
    >
    >

      My System SpecsSystem Spec

  6. #5


    Thomas Lee Guest

    Re: Determine 32 bit or 64 bit of an OS

    In message <O5iQpwskKHA.1824@newsgroup>, Charlie Russel - MVP
    <Charlie@newsgroup> writes

    >$ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if 64-bit.
    Only if you run this command from a 64-bit powershell prompt. If you run
    it from a 32-bit console you get this:


    PSH [C:\foo]: ls envrocessor*

    Name Value
    ---- -----
    PROCESSOR_ARCHITECTURE x86
    PROCESSOR_ARCHITEW6432 AMD64
    PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    GenuineIntel
    PROCESSOR_LEVEL 6
    PROCESSOR_REVISION 1706

    >
    When run from a 64-bit prompt you get:
    PSH [C:\foo]: ls envroc*

    Name Value
    ---- -----
    PROCESSOR_ARCHITECTURE AMD64
    PROCESSOR_LEVEL 6
    PROCESSOR_REVISION 1706
    PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    GenuineIntel
    --
    Thomas Lee
    doctordns@newsgroup

      My System SpecsSystem Spec

  7. #6


    Bob Landau Guest

    Re: Determine 32 bit or 64 bit of an OS

    Thomas,

    I guess it all depends on whether you want to know whether you're in a 32
    bit process or OS. IT Staff has stated OS so I guess what you've pointed out
    is important.

    Here is what I used to determine whether this is a 64 bit OS or not. This as
    you've pointed out will work in 32/64 bit OS as well as WOW

    if ($ENV:Processor_Architecture -eq 'x86' -and (test-path
    env:\PROCESSOR_ARCHITEW6432))
    {
    echo 'WOW layer 64 bit OS/32 bit process'
    }
    elseif ($ENV:Processor_Architecture -eq 'x86')
    {
    echo '32 bit OS'
    }
    elseif ($ENV:Processor_Architecture -eq 'AMD64')
    {
    echo '64 bit OS'
    }
    else
    {
    echo 'Unknown'
    }



    "Thomas Lee" wrote:

    > In message <O5iQpwskKHA.1824@newsgroup>, Charlie Russel - MVP
    > <Charlie@newsgroup> writes

    > >$ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if 64-bit.
    >
    > Only if you run this command from a 64-bit powershell prompt. If you run
    > it from a 32-bit console you get this:
    >
    >
    > PSH [C:\foo]: ls envrocessor*
    >
    > Name Value
    > ---- -----
    > PROCESSOR_ARCHITECTURE x86
    > PROCESSOR_ARCHITEW6432 AMD64
    > PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    > GenuineIntel
    > PROCESSOR_LEVEL 6
    > PROCESSOR_REVISION 1706

    > >
    >
    > When run from a 64-bit prompt you get:
    > PSH [C:\foo]: ls envroc*
    >
    > Name Value
    > ---- -----
    > PROCESSOR_ARCHITECTURE AMD64
    > PROCESSOR_LEVEL 6
    > PROCESSOR_REVISION 1706
    > PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    > GenuineIntel
    > --
    > Thomas Lee
    > doctordns@newsgroup
    > .
    >

      My System SpecsSystem Spec

  8. #7


    Charlie Russel - MVP Guest

    Re: Determine 32 bit or 64 bit of an OS

    32-bit console? What's that? <grin>


    --
    Charlie.
    http://msmvps.com/blogs/russel




    "Thomas Lee" <tfl@newsgroup> wrote in message
    news:REKkVkrgp2SLFA0V@newsgroup

    > In message <O5iQpwskKHA.1824@newsgroup>, Charlie Russel - MVP
    > <Charlie@newsgroup> writes

    >>$ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if 64-bit.
    >
    > Only if you run this command from a 64-bit powershell prompt. If you run
    > it from a 32-bit console you get this:
    >
    >
    > PSH [C:\foo]: ls envrocessor*
    >
    > Name Value
    > ---- -----
    > PROCESSOR_ARCHITECTURE x86
    > PROCESSOR_ARCHITEW6432 AMD64
    > PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    > GenuineIntel
    > PROCESSOR_LEVEL 6
    > PROCESSOR_REVISION 1706

    >>
    >
    > When run from a 64-bit prompt you get:
    > PSH [C:\foo]: ls envroc*
    >
    > Name Value
    > ---- -----
    > PROCESSOR_ARCHITECTURE AMD64
    > PROCESSOR_LEVEL 6
    > PROCESSOR_REVISION 1706
    > PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6,
    > GenuineIntel
    > --
    > Thomas Lee
    > doctordns@newsgroup

      My System SpecsSystem Spec

  9. #8


    Joe Morris Guest

    Re: Determine 32 bit or 64 bit of an OS

    "Charlie Russel - MVP" wrote:

    > "Thomas Lee" wrote:

    >> Charlie Russel - MVP wrote:

    >>>$ENV:Processor_Architecture will yield x86 if 32-bit and AMD64 if 64-bit.

    >> Only if you run this command from a 64-bit powershell prompt. If you run
    >> it from a 32-bit console you get this:

    >> PROCESSOR_ARCHITECTURE x86
    >> PROCESSOR_ARCHITEW6432 AMD64

    >> When run from a 64-bit prompt you get:
    >> PSH [C:\foo]: ls envroc*

    >> PROCESSOR_ARCHITECTURE AMD64

    > 32-bit console? What's that? <grin>
    Answer: one of the less-well-publicized pieces of 64-bit Windows. I hadn't
    expected the difference in the reported value of PROCESSOR_ARCHITECTURE (a
    tip o' the hat to Thomas for that bit of information!), so it looks like a
    more reliable test than the one for PROCESSOR_ARCHITECTURE that I proposed
    upthread, and which was echoed by Charlie, could be redesigned to declare
    the system to be a 64-bit platform if either the environment variable
    PROCESSOR_ARCHITEW6432 exists, *or* the environment variable
    PROCESSOR_ARCHITECTURE has a value of "AMD64".

    Perhaps a more reliable test (the above environment variables could be set
    by a hacker, or a student with not enough work to keep him busy) would be to
    test for the existence of the Registry data item

    HKLM\Software\Microsoft\Windows\CurrentVersion [ProgramFilesDir (x86)]

    which hopefully isn't writable by normal users.

    Joe



      My System SpecsSystem Spec

  10. #9


    IT Staff Guest

    Re: Determine 32 bit or 64 bit of an OS

    Is there a 3rd party tool or net framework class to determine it ?




      My System SpecsSystem Spec

  11. #10


    Thomas Lee Guest

    Re: Determine 32 bit or 64 bit of an OS

    In message <urukABykKHA.4912@newsgroup>, Charlie Russel - MVP
    <Charlie@newsgroup> writes

    >32-bit console? What's that? <grin>
    A strange anachronism from a deep and distant past?

    Or one of the things that PowerShell added into Windows 7...

    Thomas
    --
    Thomas Lee
    doctordns@newsgroup

      My System SpecsSystem Spec


Determine 32 bit or 64 bit of an OS
Similar Threads
Thread Forum
Determine OS on box Server General
how do i determine the OU structure on the fly ? PowerShell
determine app is 32 or 64 bit PowerShell
determine app is 32 or 64 bit Server General
determine if PC is on a certain network VB Script