16.5 Opening and Reading Registry ValuesLet's start our exploration of the Registry by finding out how to get information out of it. As an example, let's see what we can find out about the current build version of Windows NT on our system. If you're using this book on a Windows 95 system, you'll need to change the Windows NT key to Windows : use Win32::Registry; $p = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; $main::HKEY_LOCAL_MACHINE->Open($p, $CurrVer) || die "Open: $!"; $CurrVer->GetValues(\%vals); # get sub keys and value -hash ref foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[0] = $$key[2]\n"; # see below for explanation } Running this script on one of our systems produces the following output: CurrentBuildNumber: 1381 CSDVersion = Service Pack 3 CurrentBuild = 1.511.1 () (Obsolete data - do not use) RegisteredOrganization = Axiom Technologies CurrentType = Uniprocessor Free InstallDate = Ö?L3 RegisteredOwner = Erik Olson CurrentVersion = 4.0 SystemRoot = D:\NT CurrentBuildNumber = 1381 SoftwareType = SYSTEM ProductId = 50036419013877247607 SourcePath = E:\I386 PathName = D:\NT
Let's see what's going on here. The first line of the script employs the
Line four uses the foreach $k (keys %vals) { # iterate over keys $key = $vals{$k}; # get ref to list print "$$key[0] = $$key[2]\n"; # dereference as list }
We've seen how the use Win32::Registry; $main::HKEY_CURRENT_USER->Open("SOFTWARE", $Software) || die "Open: $!"; $Software->Create("ERIKO", $eriko) || die "Create: $!"; # new key is in $eriko
In order to create a key under |
|