1

I need to get unique hardware identifier, so I read MachineGuid from windows registry.

I have virtualbox machine with strawberry perl on Windows 7, and pc with Windows 7 too but without perl interpreter. This code works in virtualbox, but when I pack it to exe with PerlApp and try to execute on real machine it can`t get guid value.

use Win32::TieRegistry qw(:KEY_);       
use warnings;

$Registry = $Registry->Open('', {Access => KEY_READ(), Delimiter => "/"});
my $guid = $Registry->{'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Cryptography//MachineGuid'};
if ($guid) {
    print "guid = $guid\n";
} else {
    print "failed to get MachineGuid!\n";
}
Artem
  • 517
  • 1
  • 7
  • 24
  • 1
    [You cannot reliably read this value from the registry directly.](http://stackoverflow.com/questions/14213020/) (Reading directly from the registry is usually the wrong answer anyway.) [You should be using WMI instead.](https://msdn.microsoft.com/en-us/library/aa394105.aspx) [However, this value is NOT guaranteed to be unique across Windows installations!](http://stackoverflow.com/questions/30676726/is-hkey-local-machine-software-microsoft-cryptography-machineguid-unique) If the caveats are not good enough, you'll need another way to ensure machine uniqueness. – andlabs Nov 22 '15 at 22:45
  • Which WQL query gives me guid? – Artem Nov 23 '15 at 13:46
  • I try another way: `my $result = \`reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography -v MachineGuid\`;` `my ($guid) = $result =~ /([0-9a-z\-]{36})/i;` Error: The system was unable to find the specified registry key or value But when I manually type in console `reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography -v MachineGuid`, it returns guid. – Artem Nov 23 '15 at 14:58

0 Answers0