Chinaunix
标题:
Perl 对 Windows 注册表的操作
[打印本页]
作者:
life-boy
时间:
2011-03-23 22:41
标题:
Perl 对 Windows 注册表的操作
[代码] 新建键值
use Win32::Registry ;
$key = "SOFTWARE\\newKey";
$HKEY_LOCAL_MACHINE->Open($key, $keyList);
print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
$keyList->GetKeys(\@subKeys);
$numberOfSubKeys = @subKeys;
print "\tThere is $numberOfSubKeys key\n";
foreach $subKey (@subKeys){
print "\t\t$subKey\n";
}
print "\nCreating the Perl6 Key\n";
$keyList->Create("Perl6",$newKeyList);
print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
$keyList->GetKeys(\@newSubKeys);
$numberOfSubKeys = @newSubKeys;
print "\tThere are now $numberOfSubKeys keys\n";
foreach $subKey (@newSubKeys){
print "\t\t$subKey\n";
}
$keyList->Close();
$newKeyList->Close();
复制代码
[代码] 删除键值
use Win32::Registry;
$key = "SOFTWARE\\yourValue";
$HKEY_LOCAL_MACHINE->Open($key, $keyList);
print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
$keyList->GetKeys(\@subKeys);
$numberOfSubKeys = @subKeys;
print "\tThere are $numberOfSubKeys keys\n";
foreach $subKey (@subKeys){
print "\t\t$subKey\n";
}
$key = "newKey";
print "\nDeleting the $key Key\n";
if (!$keyList->DeleteKey($key)){
print "Failed to delete $key\n";
}
print "Under HKEY_LOCAL_MACHINE\n\tyourValue\n";
$keyList->GetKeys(\@newSubKeys);
$numberOfSubKeys = @newSubKeys;
print "\tThere are now $numberOfSubKeys key\n";
foreach $subKey (@newSubKeys){
print "\t\t$subKey\n";
}
$keyList->Close();
复制代码
[代码] 创建新键
#!/usr/bin/perl -w
use Win32::Registry;
$key_name = "SOFTWARE\\YourKey";
$status = $HKEY_LOCAL_MACHINE->Create( $key_name, $keyobj );
if ($status) {
$keyobj->SetValueEx( 'Value', # Name
0, # Reserved.
REG_SZ, # Type
'Comments' );
$keyobj->Close();
}
复制代码
[代码] 读取注册表信息
use Win32::Registry;
$| = 1;
$key = "HARDWARE";
$HKEY_LOCAL_MACHINE->Open($key, $nextKeyList);
listKeys($nextKeyList);
sub listKeys(){
$count++;
my ($keyList) = @_;
my ($nextObj, @subKeys, $subKey);
$keyList->GetKeys(\@subKeys);
foreach $subKey (@subKeys){
$tabString = " " x $count;
print "$tabString $subKey\n";
$keyList->Open($subKey, $nextKeyList);
listKeys($nextKeyList);
$count--;
}
$keyList->Close();
}
复制代码
作者:
brainwang198206
时间:
2011-05-06 11:08
回复
1#
life-boy
学习了,非常感谢。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2