views:

492

answers:

3

Using Perl, how can I determine whether my program is running on 32 bit Windows or 64 bit Windows?

Is there any API available?

I can think of a couple of options..

  1. Check the PE_HEADER of some windows file (eg: c:\windows\explorer.exe) - maybe I can use the details in How can I test a windows dll to determine if it is 32bit or 64bit?

  2. Check for the existence of c:\program files(x86) - if it exists then it is a 64 bit OS. Else it is a 32 bit windows OS.

Is there any good way of doing this? Any API available in Perl?

+2  A: 

Perhaps you can just check some environment variables:

See HOWTO: Detect Process Bitness.

kolbyjack
+1  A: 

The PROCESSOR_ARCHITECTURE variable is "x86" in 32bits

Max Caceres
And in 64bit, if running a 32bit process.
Brian
+6  A: 
Sinan Ünür
I have checked this on 32 bit Windows 7 on a 64 bit processor. Works like a breeze. Will check this on 64 bit windows 7 on 64 bit processor when i get to work on monday.
Santhosh
When i test this on Windows 7 64 bit using 32 bit Perl installer (installing in WOW mode), i see the bitness as 32 surprisingly !! And then i uninstalled 32 bit perl and installed 64 bit perl but there is a problem with it - i cannot download and install the Sys-Info package "ppm install Sys-Info" says that Sys-Info is not found. Any comments on how i can do this in 64 bit Windows?
Santhosh