使用 Perl 解析 Windows 注册表 [英] Parsing windows registry using Perl

查看:47
本文介绍了使用 Perl 解析 Windows 注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 perl 脚本来访问 Windows 注册表树结构中的值.

I am writing up a perl script to access the values from the windows registry tree structure.

我正在使用以下简单脚本

I am using the following simple script

use Win32::TieRegistry;
my $mykey = $Registry->{'HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/BIOS/'};
my $mykeyval = $mykey->{'/SystemVersion'};

print " value  $mykeyval";
exit;    

但我无法获取内容或价值

But I am unable to get the content or value

用法:Win32API::Registry::regConstant("CONST_NAME") 在 C:/Dwimperl/perl/vendor/lib/Win32/TieRegistry.pm 第 292 行

Usage: Win32API::Registry::regConstant("CONST_NAME") at C:/Dwimperl/perl/vendor/lib/Win32/TieRegistry.pm line 292

向我提供解决方案.致谢.

Provide me through the solution towards it. Thanks in adv.

推荐答案

我认为这是因为在运行 perl 脚本时没有获得管理员权限,如果您在某些平台上,例如 Win 7Win Vista.

I think that's because you don't get the Administrator permissions when running your perl script, if you're on some platform such as Win 7 or Win Vista.

某些字段的注册表键值,例如HKEY_LOCAL_MACHINE 下的那些,普通用户是无法访问的.您可以尝试以管理员身份运行脚本并观察结果.

The registry key-value of some fields, for example the ones under HKEY_LOCAL_MACHINE, are not accessible to normal users. You could try to run your script as Administrator and watch the result.

另外,Win32::TieRegistry 的默认分隔符是\\.所以如果你想使用 / 作为分隔符,你应该像这样导入模块:

In addition, the default delimiter of Win32::TieRegistry is \\. So if you would like to use / as delimiter, you should import the module like this:

use Win32::TieRegistry (Delimiter => '/');

注意,即使你的代码是正确的,如果你的SystemVersion是空白的,或者你的注册表中没有这样的键,仍然可能没有输出.所以也可以使用 Data::Dumper 打印 mykey 来检查一下.

Attention, even if your code is correct, there still could be no output, if your SystemVersion is blank, or there's no such key in your registry. So also use Data::Dumper to print mykey to check it.

这篇关于使用 Perl 解析 Windows 注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆