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

后端 未结 5 528
悲&欢浪女
悲&欢浪女 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:27

    Testing for the existence of HKEY_LOCAL_MACHINE\Software\Wow6432Node is the most reliable method

     #!/usr/bin/perl
    
    use strict; 
    use Win32::Registry;
    
    my $bitReturn = &bitter();
    
    print "OS Bit: $bitReturn \n";
    
    # Testing for the existence of HKEY_LOCAL_MACHINE\Software\Wow6432Node is the most reliable method
    sub bitter {
        my $Register = "Software\\Wow6432Node";
        my ($hkey,$bitReturn);
    
        if ($HKEY_LOCAL_MACHINE->Open($Register,$hkey)) {
            $bitReturn = "64";
        }
        else {
            $bitReturn = "32"
        }
        return $bitReturn;
    }
    

    Here is another easy method, checking Environment Variables

    sub bitter {
         my $bit;
         my $OSbit = `set`;
         if ($OSbit =~ m/Files\(x86\)/i) {
             $bit = "64";
         }
         else {
             $bit = "32";
         }
         return $bit;
    }
    

提交回复
热议问题