How can I determine the bitness of the OS using Perl on Windows?

后端 未结 5 539
悲&欢浪女
悲&欢浪女 2020-12-31 13:11

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 opt

5条回答
  •  没有蜡笔的小新
    2020-12-31 13:43

    MSDN recommends this logic (jeezus, why does this have to be so complicated?) http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx

    IF PROCESSOR_ARCHITECTURE == amd64 OR
       PROCESSOR_ARCHITEW6432 == amd64 THEN
       // OS is 64bit
    ELSE
       // OS is 32bit
    END IF
    

    here's how I used it in my script (note that the MSDN example messes up the capitalization of the variable values, at least on Win7, so I do a case insensitive compare)

    if (uc($ENV{PROCESSOR_ARCHITECTURE}) eq "AMD64" || 
        uc($ENV{PROCESSOR_ARCHITEW6432}) eq "AMD64") {
        push @impactBinaries,  "C:/Xilinx/13.1/LabTools/LabTools/bin/nt64/impact.exe";
    } else {
        push @impactBinaries,  "C:/Xilinx/13.1/LabTools/LabTools/bin/nt/impact.exe";
    }
    

提交回复
热议问题