为什么 Win32::TieRegistry 无法列出子项?

发布于 2024-07-15 12:08:17 字数 1511 浏览 11 评论 0原文

使用 Cygwin Perl v5.8.8 和 Win32::TieRegistry 0.26。

我们可以为 HKEY_CURRENT_USER 获取绑定哈希对象:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );

这适用于子键:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );

我们可以打印该键的信息:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->Information;'
$VAR1 = 'CntSubKeys';
$VAR2 = 48;
$VAR3 = 'MaxSubClassLen';
$VAR4 = 21;
...

但是文档暗示我们可以简单地通过将其视为哈希来列出子键:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key; '

但是数组是空的。 它坏了还是我做错了什么? 还有其他方法列出子键吗?

这也不起作用:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->SubKeyNames;'
Can't use an undefined value as an ARRAY reference at
/usr/lib/perl5/vendor_perl/5.8/cygwin/Win32/TieRegistry.pm line 720.

Using Cygwin Perl v5.8.8 and Win32::TieRegistry 0.26.

We can get a tied hash object thing for HKEY_CURRENT_USER:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );

And this works for sub keys:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );

And we can print information for the key:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->Information;'
$VAR1 = 'CntSubKeys';
$VAR2 = 48;
$VAR3 = 'MaxSubClassLen';
$VAR4 = 21;
...

However the documentation implies we can list the sub keys simply by treating it as a hash:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key; '

But the array is empty. Is it broken or am I doing something wrong? Is there another way to list the sub keys?

This doesn't work either:

$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->SubKeyNames;'
Can't use an undefined value as an ARRAY reference at
/usr/lib/perl5/vendor_perl/5.8/cygwin/Win32/TieRegistry.pm line 720.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残疾 2024-07-22 12:08:17

使用您的代码:

my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key;

我在我的机器上得到了这个结果(WinXP,ActiveState Perl v5.10.0,Win32-TieRegistry 0.25):

$VAR1 = 'Adobe\\';
...
$VAR101 = 'Classes\\';
$VAR102 = '\\';

这就是我从您的第二个代码示例中得到的结果:

$VAR1 = 'Adobe';
...
$VAR101 = 'Classes';

所以您的两个代码示例在 ActiveState Perl 上都工作正常至少是Windows XP。

编辑:这看起来像一个更普遍的问题/错误:

With your code:

my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key;

I get this result on my machine (WinXP, ActiveState Perl v5.10.0, Win32-TieRegistry 0.25):

$VAR1 = 'Adobe\\';
...
$VAR101 = 'Classes\\';
$VAR102 = '\\';

and this is what I get with your second code sample:

$VAR1 = 'Adobe';
...
$VAR101 = 'Classes';

So both of your code samples work okay, on ActiveState Perl and Windows XP at least.

EDIT: This looks like a more general problem/bug:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文