in reply to Need help with Win32::TieRegistry

Hello CrashBlossom,

you need administrative rights to fetch this (be also aware, not this case, of Registry Redirection: search it in my bibliotheca)

perl -MData::Dump -MWin32 -e " print Win32::IsAdminUser()?qq(ADMIN\n):qq(NOT admin\n); use Win32::TieRegistry(Delimiter=>'/'); my $idval = $Registry->'HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System +/CentralProcessor/0'}; dd $idval " NOT admin undef #launched portableshell.bat as administrator: perl -MData::Dump -MWin32 -e " print Win32::IsAdminUser()?qq(ADMIN\n):qq(NOT admin\n); use Win32::TieRegistry(Delimiter=>'/'); my $idval = $Registry->'HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System +/CentralProcessor/0'}; dd $idval " ADMIN bless({ # tied Win32::TieRegistry "/Component Information" => "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", "/Configuration Data" => pack("H*","ffffffffffffffff000000000 +0000000"), "/FeatureSet" => "0x3D1B3FFF", "/Identifier" => "Intel64 Family 6 Model 94 Stepping +3", "/Platform Specific Field 1" => "0x00000002", "/Previous Update Revision" => "\0\0\0\0\xA0\0\0\0", "/ProcessorNameString" => "Intel(R) Core(TM) i5-6400 CPU \@ 2. +70GHz", "/Update Revision" => "\0\0\0\0\xC6\0\0\0", "/Update Status" => "0x00000000", "/VendorIdentifier" => "GenuineIntel", "/~MHz" => "0x00000A98", }, "Win32::TieRegistry")

L*

PS you also have a (not influencing results) double delimiter in /0//Identifier

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Need help with Win32::TieRegistry
by holli (Abbot) on Jul 01, 2019 at 10:48 UTC
    you need administrative rights to fetch this
    Do you? Win32::SystemInfo works with user privileges. And the module is reading from the Registry too. Addendum: It is using a combination of Win32::TieRegistry and the GetSystemInfo function from Win32::API. Here's the relevant function.
    use Win32::SystemInfo; use Data::Dumper; my %phash; Win32::SystemInfo::ProcessorInfo(%phash); print Dumper (\%phash);
    Yields on my system, running as normal user:
    $VAR1 = { 'Processor3' => { 'Identifier' => 'Intel64 Family 6 Model 60 + Stepping 3', 'ProcessorName' => 'Intel(R) Core(TM) i5-4 +440 CPU @ 3.10GHz', 'VendorIdentifier' => 'GenuineIntel', 'MHZ' => 3093 }, 'NumProcessors' => 4, 'Processor2' => { 'MHZ' => 3093, 'VendorIdentifier' => 'GenuineIntel', 'Identifier' => 'Intel64 Family 6 Model 60 + Stepping 3', 'ProcessorName' => 'Intel(R) Core(TM) i5-4 +440 CPU @ 3.10GHz' }, 'Processor0' => { 'MHZ' => 3093, 'VendorIdentifier' => 'GenuineIntel', 'ProcessorName' => 'Intel(R) Core(TM) i5-4 +440 CPU @ 3.10GHz', 'Identifier' => 'Intel64 Family 6 Model 60 + Stepping 3' }, 'Processor1' => { 'ProcessorName' => 'Intel(R) Core(TM) i5-4 +440 CPU @ 3.10GHz', 'Identifier' => 'Intel64 Family 6 Model 60 + Stepping 3', 'VendorIdentifier' => 'GenuineIntel', 'MHZ' => 3093 } };


    holli

    You can lead your users to water, but alas, you cannot drown them.
      After reading holli's observation that SystemInfo uses TieRegistry, I took look at the source for SystemInfo. The following bit at the top is lifted almost verbatim from SystemInfo:
      use strict; use warnings; use Win32::TieRegistry qw(:KEY_); $Registry->Delimiter("/"); my $procinfo = $Registry->Open( "HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/Centra +lProcessor/0", { Access => KEY_READ() } ); PrintHash($procinfo); sub PrintHash { my ($hashref, $indent) = @_; my %hash = %{$hashref}; $indent += 2; my $maxsize = 0; foreach my $key (keys %hash) { $maxsize = length $key if (length $key > $maxsize); } foreach my $key (sort keys %hash) { printf "%*sKey: %-*s Value: %s\n", $indent, "", $maxsize, $key +, $hash{$key}; if (ref $hash{$key} eq 'ARRAY') { PrintArray($hash{$key}, $ind +ent); } if (ref $hash{$key} eq 'HASH') { PrintHash($hash{$key}, $inde +nt); } } } sub PrintArray { my ($array, $indent) = @_; my @arr = @{$array}; $indent += 2; my $cnt = 0; foreach my $elem (@arr) { printf("%*s%2d. %s\n", $indent, "", $cnt, $elem); if (ref $elem eq 'ARRAY') { PrintArray($elem, $indent); } if (ref $elem eq 'HASH') { PrintHash($elem, $indent); } ++$cnt; } }
      Here is the result:
      Key: /Component Information Value: Key: /Configuration Data Value:          Key: /FeatureSet Value: 0x3D1B3FFF Key: /Identifier Value: Intel64 Family 6 Model 60 Ste +pping 3 Key: /Platform Specific Field 1 Value: 0x00000020 Key: /Previous Update Revision Value:  Key: /ProcessorNameString Value: Intel(R) Core(TM) i7-4700HQ C +PU @ 2.40GHz Key: /Update Revision Value: % Key: /Update Status Value: 0x00000000 Key: /VendorIdentifier Value: GenuineIntel Key: /~MHz Value: 0x0000095A

      Apparently "Access => KEY_READ()" indicates that read-only access is requested, which makes everything good.

      Thanks for the responses. This issue is resolved

      I suppose TieRegistry requires admin rights because it allows you to change the registry. In any case, SystemInfo provides the information I need for this particular problem, so thanks for the tip!