Setting Registry Values
In addition to creating keys, we can also
set Registry values. To do so, we once again need an open key and the
SetValue
or
SetValueEx function. SetValue
sets the default (unnamed) value for a key, while
SetValueEx allows you to create a new named value
and set its information. The following example assumes that we
already have the $eriko key open:
$eriko->SetValue("blah", REG_SZ, "some_string");
$eriko->SetValueEx("foo", 0, REG_SZ, "bar");Even though these two functions look similar, they do quite different
things. The first line (SetValue) creates a new
key called blah and sets its default (unnamed)
value to some_string. The second line
(SetValueEx) creates a new value under
$eriko with a name of foo and a
value of bar. In both cases, we’re using the
REG_SZ data type, which indicates string data.
More Registry Operations
You can do more with the Registry than just read and modify key values. You can also delete keys and export/import hives from the Registry. As we mentioned above, be extremely prudent when deleting or importing things into your registry.
Here’s an example of deleting a key:
use Win32::Registry;
$main::HKEY_CURRENT_USER->Open("SOFTWARE", $Software) ||
die "Open: $!";
$Software->Create("ERIKO", $eriko) ||
die "Create: $!"; # open parent key
$eriko->DeleteKey("blah"); # delete blah
DeleteKey
will delete a key and all of its values—it will
not delete a key with subkeys. To do that, you need to remove all of the subkeys first. Here’s how you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access