• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Determine 32 bit or 64 bit of an OS

C

Charlie Russel - MVP

#2
$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]::osversion
> $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 Computer

K

Karl Mitschke

#3
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]::osversion
>> $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 Computer

C

Charlie Russel - MVP

#4
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]::osversion
>>> $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 Computer

T

Thomas Lee

#5
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 env:processor*

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 env:proc*

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 Computer

B

Bob Landau

#6
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 env:processor*
>
> 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 env:proc*
>
> 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 Computer

C

Charlie Russel - MVP

#7
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 env:processor*
>
> 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 env:proc*
>
> 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 Computer

J

Joe Morris

#8
"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 env:proc*

>> 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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)