免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3857 | 回复: 1
打印 上一主题 下一主题

Perl 对 Windows 注册表的操作 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-23 22:41 |只看该作者 |倒序浏览
[代码] 新建键值
  1. use Win32::Registry ;

  2. $key = "SOFTWARE\\newKey";
  3. $HKEY_LOCAL_MACHINE->Open($key, $keyList);
  4. print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
  5. $keyList->GetKeys(\@subKeys);
  6. $numberOfSubKeys = @subKeys;
  7. print "\tThere is $numberOfSubKeys key\n";
  8. foreach $subKey (@subKeys){
  9.    print "\t\t$subKey\n";
  10. }
  11. print "\nCreating the Perl6 Key\n";
  12. $keyList->Create("Perl6",$newKeyList);
  13. print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
  14. $keyList->GetKeys(\@newSubKeys);
  15. $numberOfSubKeys = @newSubKeys;
  16. print "\tThere are now $numberOfSubKeys keys\n";
  17. foreach $subKey (@newSubKeys){
  18.       print "\t\t$subKey\n";
  19. }
  20. $keyList->Close();
  21. $newKeyList->Close();
复制代码
[代码] 删除键值
  1. use Win32::Registry;

  2. $key = "SOFTWARE\\yourValue";
  3. $HKEY_LOCAL_MACHINE->Open($key, $keyList);
  4. print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
  5. $keyList->GetKeys(\@subKeys);
  6. $numberOfSubKeys = @subKeys;
  7. print "\tThere are $numberOfSubKeys keys\n";
  8. foreach $subKey (@subKeys){
  9.    print "\t\t$subKey\n";
  10. }
  11. $key = "newKey";
  12. print "\nDeleting the $key Key\n";
  13. if (!$keyList->DeleteKey($key)){
  14.    print "Failed to delete $key\n";
  15. }
  16. print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
  17. $keyList->GetKeys(\@newSubKeys);
  18. $numberOfSubKeys = @newSubKeys;
  19. print "\tThere are now $numberOfSubKeys key\n";
  20. foreach $subKey (@newSubKeys){
  21.    print "\t\t$subKey\n";
  22. }
  23. $keyList->Close();
复制代码
[代码] 创建新键
  1. #!/usr/bin/perl -w

  2. use Win32::Registry;

  3. $key_name = "SOFTWARE\\YourKey";

  4. $status = $HKEY_LOCAL_MACHINE->Create( $key_name, $keyobj );

  5. if ($status) {

  6.     $keyobj->SetValueEx( 'Value',  # Name
  7.         0,        # Reserved.
  8.         REG_SZ,   # Type
  9.         'Comments' );


  10.     $keyobj->Close();
  11. }
复制代码
[代码] 读取注册表信息
  1. use Win32::Registry;
  2. $| = 1;
  3. $key = "HARDWARE";
  4. $HKEY_LOCAL_MACHINE->Open($key, $nextKeyList);
  5. listKeys($nextKeyList);
  6. sub listKeys(){
  7.    $count++;
  8.    my ($keyList) = @_;
  9.    my ($nextObj, @subKeys, $subKey);
  10.    $keyList->GetKeys(\@subKeys);
  11.    foreach $subKey (@subKeys){
  12.       $tabString = "   " x $count;
  13.       print "$tabString $subKey\n";
  14.       $keyList->Open($subKey, $nextKeyList);
  15.       listKeys($nextKeyList);
  16.       $count--;
  17.    }
  18.    $keyList->Close();
  19. }
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-05-06 11:08 |只看该作者
回复 1# life-boy


  学习了,非常感谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP