Win32::TieRegistry - Manipulate the Win32 Registry |
Win32::TieRegistry - Manipulate the Win32 Registry
use Win32::TieRegistry 0.20 ( UseOptionName=>UseOptionValue[,...] );
$Registry->SomeMethodCall(arg1,...);
$subKey= $Registry->{"Key\\SubKey\\"}; $valueData= $Registry->{"Key\\SubKey\\\\ValueName"}; $Registry->{"Key\\SubKey\\"}= { "NewSubKey" => {...} }; $Registry->{"Key\\SubKey\\\\ValueName"}= "NewValueData"; $Registry->{"\\ValueName"}= [ pack("fmt",$data), REG_DATATYPE ];
use Win32::TieRegistry( Delimiter=>"#", ArrayValues=>0 ); $pound= $Registry->Delimiter("/"); $diskKey= $Registry->{"LMachine/System/Disk/"} or die "Can't read LMachine/System/Disk key: $^E\n"; $data= $diskKey->{"/Information"} or die "Can't read LMachine/System/Disk//Information value: $^E\n"; $remoteKey= $Registry->{"//ServerA/LMachine/System/"} or die "Can't read //ServerA/LMachine/System/ key: $^E\n"; $remoteData= $remoteKey->{"Disk//Information"} or die "Can't read ServerA's System/Disk//Information value: $^E\n"; foreach $entry ( keys(%$diskKey) ) { ... } foreach $subKey ( $diskKey->SubKeyNames ) { ... } $diskKey->AllowSave( 1 ); $diskKey->RegSaveKey( "C:/TEMP/DiskReg", [] );
The Win32::TieRegistry module lets you manipulate the Registry via objects [as in ``object oriented''] or via tied hashes. But you will probably mostly use a combination reference, that is, a reference to a tied hash that has also been made an object so that you can mix both access methods [as shown above].
If you did not get this module as part of libwin32, you might want to get a recent version of libwin32 from CPAN which should include this module and the Win32API::Registry module that it uses.
Skip to the SUMMARY section if you just want to dive in and start using the Registry from Perl.
Accessing and manipulating the registry is extremely simple using Win32::TieRegistry. A single, simple expression can return you almost any bit of information stored in the Registry. Win32::TieRegistry also gives you full access to the ``raw'' underlying API calls so that you can do anything with the Registry in Perl that you could do in C. But the ``simple'' interface has been carefully designed to handle almost all operations itself without imposing arbitrary limits while providing sensible defaults so you can list only the parameters you care about.
But first, an overview of the Registry itself.
The Registry is a forest: a collection of several tree structures. The root of each tree is a key. These root keys are identified by predefined constants whose names start with ``HKEY_''. Although all keys have a few attributes associated with each [a class, a time stamp, and security information], the most important aspect of keys is that each can contain subkeys and can contain values.
Each subkey has a name: a string which cannot be blank and cannot
contain the delimiter character [backslash: '\\'
] nor nul
['\0'
]. Each subkey is also a key and so can contain subkeys
and values [and has a class, time stamp, and security information].
Each value has a name: a string which can be blank and can
contain the delimiter character [backslash: '\\'
] and any
character except for null, '\0'
. Each value also has data
associated with it. Each value's data is a contiguous chunk of
bytes, which is exactly what a Perl string value is so Perl
strings will usually be used to represent value data.
Each value also has a data type which says how to interpret the value data. The primary data types are:
'%'
], an environment variable name, then a percent
sign, that should be replaced with the value associate with that
environment variable. The system does not automatically do this
substitution.
If your system has the SetDualVar module installed,
the DualBinVals()
option wasn't turned off, and you
fetch a REG_BINARY
value of 4 bytes or fewer, then
you can use the returned value in a numeric context to
get at the ``unpacked'' numeric value. See GetValue()
for more information.
'\0'
at the end of the list. Note that the list
can include empty strings so use the value's length to determine
the end of the list, not the first occurrence of '\0\0'
.
It is best to set the SplitMultis()
option so Win32::TieRegistry
will split these values into an array of strings for you.
How such values are returned depends on the DualBinVals()
and
DWordsToHex()
options. See GetValue()
for details.
In the underlying Registry calls, most places which take a
subkey name also allow you to pass in a subkey ``path'' -- a
string of several subkey names separated by the delimiter
character, backslash ['\\'
]. For example, doing
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\DISK",...)
is much
like opening the "SYSTEM"
subkey of HKEY_LOCAL_MACHINE
,
then opening its "DISK"
subkey, then closing the "SYSTEM"
subkey.
All of the Win32::TieRegistry features allow you to use your
own delimiter in place of the system's delimiter, ['\\'
]. In
most of our examples we will use a forward slash ['/'
] as our
delimiter as it is easier to read and less error prone to use when
writing Perl code since you have to type two backslashes for each
backslash you want in a string. Note that this is true even when
using single quotes -- '\\HostName\LMachine\'
is an invalid
string and must be written as '\\\\HostName\\LMachine\\'
.
You can also connect to the registry of other computers on your network. This will be discussed more later.
Although the Registry does not have a single root key, the Win32::TieRegistry module creates a virtual root key for you which has all of the HKEY_* keys as subkeys.
Before you can use a tied hash, you must create one. One way to do that is via:
use Win32::TieRegistry ( TiedHash => '%RegHash' );
which exports a %RegHash
variable into your package and ties it
to the virtual root key of the Registry. An alternate method is:
my %RegHash; use Win32::TieRegistry ( TiedHash => \%RegHash );
There are also several ways you can tie a hash variable to any other key of the Registry, which are discussed later.
Note that you will most likely use $Registry
instead of using
a tied hash. $Registry
is a reference to a hash that has
been tied to the virtual root of your computer's Registry [as if,
$Registry= \%RegHash
]. So you would use $Registry->{Key}
rather than $RegHash{Key}
and use keys %{$Registry}
rather
than keys %RegHash
, for example.
For each hash which has been tied to a Registry key, the Perl
keys
function will return a list containing the name of each
of the key's subkeys with a delimiter character appended to it and
containing the name of each of the key's values with a delimiter
prepended to it. For example:
keys( %{ $Registry->{"HKEY_CLASSES_ROOT\\batfile\\"} } )
might yield the following list value:
( "DefaultIcon\\", # The subkey named "DefaultIcon" "shell\\", # The subkey named "shell" "shellex\\", # The subkey named "shellex" "\\", # The default value [named ""] "\\EditFlags" ) # The value named "EditFlags"
For the virtual root key, short-hand subkey names are used as
shown below. You can use the short-hand name, the regular
HKEY_* name, or any numeric value to access these keys, but
the short-hand names are all that will be returned by the keys
function.
"SOFTWARE\\Classes"
subkey of the HKEY_LOCAL_MACHINE
key.
HKEY_USERS
key.
".DEFAULT"
, which gets copied to a new
subkey whenever a new user is added. Also contains a subkey for
each user of the system, though only those for active users
[usually only one] are loaded at any given time.
ERROR_INSUFFICIENT_BUFFER
. For example, you
can't enumerate key names without also enumerating values which
require huge buffers but the exact buffer size required cannot be
determined beforehand because RegQueryInfoKey()
always fails
with ERROR_INSUFFICIENT_BUFFER
for HKEY_PERFORMANCE_DATA
no
matter how it is called. So it is currently not very useful to
tie a hash to this key. You can use it to create an object to use
for making carefully constructed calls to the underlying Reg*()
routines.
A tied hash is much like a regular hash variable in Perl -- you give
it a key string inside braces, [{
and }
], and it gives you
back a value [or lets you set a value]. For Win32::TieRegistry
hashes, there are two types of values that will be returned.
[0]
and the value data type is element
[1]
.
The key string which you use in the tied hash must be interpreted to determine whether it is a value name or a key name or a path that combines several of these or even other things. There are two simple rules that make this interpretation easy and unambiguous:
Put a delimiter after each key name. Put a delimiter in front of each value name.
Exactly how the key string will be interpreted is governed by the following cases, in the order listed. These cases are designed to ``do what you mean''. Most of the time you won't have to think about them, especially if you follow the two simple rules above. After the list of cases we give several examples which should be clear enough so feel free to skip to them unless you are worried about the details.
If the hash key string starts with two delimiters in a row, then those should be immediately followed by the name of a remote machine whose registry we wish to connect to. That can be followed by a delimiter and more subkey names, etc. If the machine name is not following by anything, then a virtual root for the remote machine's registry is created, a hash is tied to it, and a reference to that hash it is returned.
"LMachine"
, an
HKEY_* value, or a numeric value]. This alternate notation is
allowed in order to be more consistent with the Open()
method
function.
For all other Registry keys, the leading delimiter indicates that the rest of the string is a value name. The leading delimiter is stripped and the rest of the string [which can be empty and can contain more delimiters] is used as a value name with no further parsing.
keys
function on the tied
hash [or have already called MemberNames
on the object] and the
hash key string exactly matches one of the strings returned, then
no further parsing is done. In other words, if the key string
exactly matches the name of a direct subkey with a delimiter
appended, then a reference to a hash tied to that subkey is
returned [but only if keys
or MemberNames
has already
been called for that tied hash].
This is only important if you have selected a delimiter other than the system default delimiter and one of the subkey names contains the delimiter you have chosen. This rule allows you to deal with subkeys which contain your chosen delimiter in their name as long as you only traverse subkeys one level at a time and always enumerate the list of members before doing so.
The main advantage of this is that Perl code which recursively traverses a hash will work on hashes tied to Registry keys even if a non-default delimiter has been selected.
If you are reading from the hash [fetching], then we first use the
key string as a value name. If there is a value with a matching
name in the Registry key which the hash is tied to, then the value
data string [and possibly the value data type] is returned.
Otherwise, we retry by using the hash key string as a subkey name.
If there is a subkey with a matching name, then we return a
reference to a hash tied to that subkey. Otherwise we return
undef
.
If you are writing to the hash [storing], then we use the key string as a subkey name only if the value you are storing is a reference to a hash value. Otherwise we use the key string as a value name.
Here are some examples showing different ways of accessing Registry information using references to tied hashes:
$tip18= $Registry->{"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\" . 'Windows\\CurrentVersion\\Explorer\\Tips\\\\18'};
Should return the text of important tip number 18. Note that two
backslashes, "\\"
, are required to get a single backslash into
a Perl double-quoted or single-qouted string. Note that "\\"
is appended to each key name ["HKEY_LOCAL_MACHINE"
through
"Tips"
] and "\\"
is prepended to the value name, "18"
.
$Registry->Delimiter("/"); $tip18= $Registry->{"HKEY_LOCAL_MACHINE/Software/Microsoft/" . 'Windows/CurrentVersion/Explorer/Tips//18'};
This usually makes things easier to read when working in Perl. All remaining examples will assume the delimiter has been changed as above.
$ms= $Registry->{"LMachine/Software/Microsoft/"}; $tips= $ms->{"Windows/CurrentVersion/Explorer/Tips/"}; $tip18= $winlogon->{"/18"};
Same as above but opens more keys into the Registry which lets you efficiently re-access those intermediate keys. This is slightly less efficient if you never reuse those intermediate keys.
$tip18= $Registry->{"LMachine/Software/Microsoft/"}-> {"Windows/CurrentVersion/Explorer/Tips/"}->{"/18"};
Like above, this creates intermediate key objects then uses them to access other data. Once this statement finishes, the intermediate key objects are destroyed. Several handles into the Registry are opened and closed by this statement so it is less efficient but there are times when this will be useful.
$tip18= $Registry->{"LMachine/Software/Microsoft"}-> {"Windows/CurrentVersion/Explorer/Tips"}->{"/18"};
Because we left off the trailing delimiters, Win32::TieRegistry
doesn't know whether final names, "Microsoft"
and "Tips"
,
are subkey names or value names. So this statement ends up
executing the same code as the next one.
$tip18= $Registry->{"LMachine/Software/"}->{"Microsoft"}-> {"Windows/CurrentVersion/Explorer/"}->{"Tips"}->{"/18"};
With more chains to go through, more temporary objects are created
and later destroyed than in our first chaining example. Also,
when "Microsoft"
is looked up, Win32::TieRegistry first
tries to open it as a value and fails then tries it as a subkey.
The same is true for when it looks up "Tips"
.
$tips= $Registry->{"LMachine/Software/Microsoft/"}-> {"Windows/CurrentVersion/Explorer/Tips/"} or die "Can't find the Windows tips: $^E\n"; foreach( keys %$tips ) { print "$_: ", $tips->{$_}, "\n"; }
First notice that we actually check for failure for the first
time. We are assuming that the "Tips"
key contains no subkeys.
Otherwise the print
statement would show something like
"Win32::TieRegistry=HASH(0xc03ebc)"
for each subkey.
The output from the above code will start something like:
/0: If you don't know how to do something,[...]
You can use the Perl delete
function to delete a value from a
Registry key or to delete a subkey as long that subkey contains
no subkeys of its own. See More Examples, below, for more
information.
You can use the Perl assignment operator [=
] to create new
keys, create new values, or replace values. The values you store
should be in the same format as the values you would fetch from a
tied hash. For example, you can use a single assignment statement
to copy an entire Registry tree. The following statement:
$Registry->{"LMachine/Software/Classes/Tie_Registry/"}= $Registry->{"LMachine/Software/Classes/batfile/"};
creates a "Tie_Registry"
subkey under the "Software\\Classes"
subkey of the HKEY_LOCAL_MACHINE
key. Then it populates it
with copies of all of the subkeys and values in the "batfile"
subkey and all of its subkeys. Note that you need to have
called $Registry->ArrayValues(1)
for the proper value data
type information to be copied. Note also that this release of
Win32::TieRegistry does not copy key attributes such as class
name and security information [this is planned for a future release].
The following statement creates a whole subtree in the Registry:
$Registry->{"LMachine/Software/FooCorp/"}= { "FooWriter/" => { "/Version" => "4.032", "Startup/" => { "/Title" => "Foo Writer Deluxe ][", "/WindowSize" => [ pack("LL",$wid,$ht), "REG_BINARY" ], "/TaskBarIcon" => [ "0x0001", "REG_DWORD" ], }, "Compatibility/" => { "/AutoConvert" => "Always", "/Default Palette" => "Windows Colors", }, }, "/License", => "0123-9C8EF1-09-FC", };
Note that all but the last Registry key used on the left-hand side of the assignment [that is, ``LMachine/Software/'' but not ``FooCorp/''] must already exist for this statement to succeed.
By using the leading a trailing delimiters on each subkey name and value name, Win32::TieRegistry will tell you if you try to assign subkey information to a value or visa-versa.
$tips= $Registry->{"LMachine/Software/Microsoft/"}-> {"Windows/CurrentVersion/Explorer/Tips/"} or die "Can't find the Windows tips: $^E\n"; $tips{'/186'}= "Be very careful when making changes to the Registry!";
$tips= $Registry->{"LMachine/Software/Microsoft/"}-> {"Windows/CurrentVersion/Explorer/Tips/"} or die "Can't find the Windows tips: $^E\n"; $tip186= delete $tips{'/186'};
Note that Perl's delete
function returns the value that was deleted.
$Registry->{"LMachine/Software/Microsoft/" . "Windows/CurrentVersion/Explorer/Tips//186"}= "Be very careful when making changes to the Registry!";
$tip186= delete $Registry->{"LMachine/Software/Microsoft/Windows/" . "CurrentVersion/Explorer/Tips//186"};
Note that this only deletes the tail of what we looked up, the
"186"
value, not any of the keys listed.
$tips= delete $Registry->{"CUser/Software/Microsoft/Windows/" . "CurrentVersion/Explorer/Tips/"};
This deletes the "Tips"
key and the values it contains. The
delete
function will return a reference to a hash [not a tied
hash] containing the value names and value data that were deleted.
The information to be returned is copied from the Registry into a
regular Perl hash before the key is deleted. If the key has many
subkeys, this copying could take a significant amount of memory
and/or processor time. So you can disable this process by calling
the FastDelete
member function:
$prevSetting= $regKey->FastDelete(1);
which will cause all subsequent delete operations via $regKey
to simply return a true value if they succeed. This optimization
is automatically done if you use delete
in a void context.
delete
to delete a Registry key or value and use
the return value, then Win32::TieRegistry usually looks up the
current contents of that key or value so they can be returned if
the deletion is successful. If the deletion succeeds but the
attempt to lookup the old contents failed, then the return value
of delete
will be $^E
from the failed part of the operation.
$Registry->{"LMachine/Software/Microsoft/Windows/" . "CurrentVersion/Explorer/Tips/"}= $tips;
This adds back what we just deleted. Note that this version of Win32::TieRegistry will use defaults for the key attributes [such as class name and security] and will not restore the previous attributes.
$res= delete $Registry->{"CUser/Software/Microsoft/Windows/"} defined($res) || die "Can't delete URL key: $^E\n";
Since the ``Windows'' key should contain subkeys, that delete
statement should make no changes to the Registry, return undef
,
and set $^E
to ``Access is denied''.
$tips= $Registry->{"CUser/Software/Microsoft/Windows/" . "CurrentVersion/Explorer/Tips/"}; delete $tips;
The Perl delete
function requires that its argument be an
expression that ends in a hash element lookup [or hash slice],
which is not the case here. The delete
function doesn't
know which hash $tips came from and so can't delete it.
The following member functions are defined for use on Win32::TieRegistry objects:
new
method creates a new Win32::TieRegistry object.
new
is mostly a synonym for Open()
so see Open()
below for
information on what arguments to pass in. Examples:
$machKey= Win32::TieRegistry->new("LMachine") or die "Can't access HKEY_LOCAL_MACHINE key: $^E\n"; $userKey= Win32::TieRegistry->new("CUser") or die "Can't access HKEY_CURRENT_USER key: $^E\n";
Note that calling new
via a reference to a tied hash returns
a simple object, not a reference to a tied hash.
Open
method opens a Registry key and returns a new
Win32::TieRegistry object associated with that Registry key.
If Open
is called via a reference to a tied hash, then Open
returns another reference to a tied hash. Otherwise Open
returns a simple object and you should then use TiedRef
to get
a reference to a tied hash.
$sSubKey
is a string specifying a subkey to be opened.
Alternately $sSubKey
can be a reference to an array value
containing the list of increasingly deep subkeys specifying the
path to the subkey to be opened.
$rhOptions
is an optional reference to a hash containing extra
options. The Open
method supports two options, "Delimiter"
and "Access"
, and $rhOptions
should have only have zero or
more of these strings as keys. See the ``Examples'' section below
for more information.
The "Delimiter"
option specifies what string [usually a single
character] will be used as the delimiter to be appended to subkey
names and prepended to value names. If this option is not specified,
the new key [$subKey
] inherits the delimiter of the old key
[$key
].
The "Access"
option specifies what level of access to the
Registry key you wish to have once it has been opened. If this
option is not specified, the new key [$subKey
] is opened with
the same access level used when the old key [$key
] was opened.
The virtual root of the Registry pretends it was opened with
access KEY_READ()|KEY_WRITE()
so this is the default access when
opening keys directory via $Registry
. If you don't plan on
modifying a key, you should open it with KEY_READ
access as
you may not have KEY_WRITE
access to it or some of its subkeys.
If the "Access"
option value is a string that starts with
"KEY_"
, then it should match one of the predefined access
levels [probably "KEY_READ"
, "KEY_WRITE"
, or
"KEY_ALL_ACCESS"
] exported by the Win32API::Registry module.
Otherwise, a numeric value is expected. For maximum flexibility,
include use Win32::TieRegistry qw(:KEY_);
, for example, near
the top of your script so you can specify more complicated access
levels such as KEY_READ()|KEY_WRITE()
.
If $sSubKey
does not begin with the delimiter [or $sSubKey
is an array reference], then the path to the subkey to be opened
will be relative to the path of the original key [$key
]. If
$sSubKey
begins with a single delimiter, then the path to the
subkey to be opened will be relative to the virtual root of the
Registry on whichever machine the original key resides. If
$sSubKey
begins with two consecutive delimiters, then those
must be followed by a machine name which causes the Connect()
method function to be called.
Examples:
$machKey= $Registry->Open( "LMachine", {Access=>KEY_READ(),Delimiter=>"/"} ) or die "Can't open HKEY_LOCAL_MACHINE key: $^E\n"; $swKey= $machKey->Open( "Software" ); $logonKey= $swKey->Open( "Microsoft/Windows NT/CurrentVersion/Winlogon/" ); $NTversKey= $swKey->Open( ["Microsoft","Windows NT","CurrentVersion"] ); $versKey= $swKey->Open( qw(Microsoft Windows CurrentVersion) );
$remoteKey= $Registry->Open( "//HostA/LMachine/System/", {Delimiter=>"/"} ) or die "Can't connect to HostA or can't open subkey: $^E\n";
Connect
method connects to the Registry of a remote machine,
and opens a key within it, then returns a new Win32::TieRegistry
object associated with that remote Registry key. If Connect
was called using a reference to a tied hash, then the return value
will also be a reference to a tied hash [or undef
]. Otherwise,
if you wish to use the returned object as a tied hash [not just as
an object], then use the TiedRef
method function after Connect
.
$sMachineName
is the name of the remote machine. You don't have
to precede the machine name with two delimiter characters.
$sKeyPath
is a string specifying the remote key to be opened.
Alternately $sKeyPath
can be a reference to an array value
containing the list of increasingly deep keys specifying the path
to the key to be opened.
$rhOptions
is an optional reference to a hash containing extra
options. The Connect
method supports two options, "Delimiter"
and "Access"
. See the Open
method documentation for more
information on these options.
$sKeyPath
is already relative to the virtual root of the Registry
of the remote machine. A single leading delimiter on sKeyPath
will be ignored and is not required.
$sKeyPath
can be empty in which case Connect
will return an
object representing the virtual root key of the remote Registry.
Each subsequent use of Open
on this virtual root key will call
the system RegConnectRegistry
function.
The Connect
method can be called via any Win32::TieRegistry
object, not just $Registry
. Attributes such as the desired
level of access and the delimiter will be inherited from the
object used but the $sKeyPath
will always be relative to the
virtual root of the remote machine's registry.
Examples:
$remMachKey= $Registry->Connect( "HostA", "LMachine", {Delimiter->"/"} ) or die "Can't connect to HostA's HKEY_LOCAL_MACHINE key: $^E\n";
$remVersKey= $remMachKey->Connect( "www.microsoft.com", "LMachine/Software/Microsoft/Inetsrv/CurrentVersion/", { Access=>KEY_READ, Delimiter=>"/" } ) or die "Can't check what version of IIS Microsoft is running: $^E\n";
$remVersKey= $remMachKey->Connect( "www", qw(LMachine Software Microsoft Inetsrv CurrentVersion) ) or die "Can't check what version of IIS we are running: $^E\n";
<$obj == $obj-
ObjectRef>>].
For a reference to a tied hash [if it is also an object], ObjectRef
returns the simple object that the hash is tied to.
This is primarily useful when debugging since typing x $Registry
will try to display your entire registry contents to your screen.
But the debugger command <x $Registry-
ObjectRef>> will just dump
the implementation details of the underlying object to your screen.
If the optional $bFlush
is specified and a true value, then
RegFlushKey()
will be called, which is almost never necessary.
$ValueData
is usually just a Perl string that contains the
value data [packed into it]. For certain types of data, however,
$ValueData
may be processed as described below.
$ValueType
is the REG_*
constant describing the type of value
data stored in $ValueData
. If the DualTypes()
option is on,
then $ValueType
will be a dual value. That is, when used in a
numeric context, $ValueType
will give the numeric value of a
REG_*
constant. However, when used in a non-numeric context,
$ValueType
will return the name of the REG_*
constant, for
example "REG_SZ"
[note the quotes]. So both of the following
can be true at the same time:
$ValueType == REG_SZ() $ValueType eq "REG_SZ"
FixSzNulls()
option is on, then the trailing '\0'
will be
stripped [unless there isn't one] before values of type REG_SZ
and REG_EXPAND_SZ
are returned. Note that SetValue()
will add
a trailing '\0'
under similar circumstances.
SplitMultis()
option is on, then values of this type are
returned as a reference to an array containing the strings. For
example, a value that, with SplitMultis()
off, would be returned as:
"Value1\000Value2\000\000"
would be returned, with SplitMultis()
on, as:
[ "Value1", "Value2" ]
DualBinVals()
option is on, then the value is returned
as a scalar containing both a string and a number [much like
the $!
variable -- see the SetDualVar module for more
information] where the number part is the ``unpacked'' value.
Use the returned value in a numeric context to access this part
of the value. For example:
$num= 0 + $Registry->{"CUser/Console//ColorTable01"};
If the DWordsToHex()
option is off, the string part of the
returned value is a packed, 4-byte string [use unpack("L",$value)
to get the numeric value.
If DWordsToHex()
is on, the string part of the returned value is
a 10-character hex strings [with leading ``0x'']. You can use
hex($value)
to get the numeric value.
Note that SetValue()
will properly understand each of these
returned value formats no matter how DualBinVals()
is set.
MemberNames()
and tied hashes.
Once you request this information, it is cached in the object and
future requests will always return the same list unless Flush()
has been called.
MemberNames()
and tied hashes.
Once you request this information, it is cached in the object and
future requests will always return the same list unless Flush()
has been called.
SubKeyNames()
.
SubKeyNames()
. Each
time is a FILETIME
structure packed into a Perl string.
Once you request this information, it is cached in the object and
future requests will always return the same list unless Flush()
has been called.
Note that a value name could end in a delimiter [or could be ""
so that the member name returned is just a delimiter] so the
presence or absence of the leading delimiter is what should be
used to determine whether a particular name is for a subkey or a
value, not the presence or absence of a trailing delimiter.
Once you request this information, it is cached in the object and
future requests will always return the same list unless Flush()
has been called.
FILETIME
structure indicating when the key was last modified
and packed into a Perl string.
SECURITY_DESCRIPTOR
associated with the Registry key.
With no arguments, returns a hash [not a reference to a hash] where the keys are the names for the items given above and the values are the information describe above. For example:
%info= ( "CntValues" => 25, # Key contains 25 values. "MaxValNameLen" => 20, # One of which has a 20-char name. "MaxValDataLen" => 42, # One of which has a 42-byte value. "CntSubKeys" => 1, # Key has 1 immediate subkey. "MaxSubKeyLen" => 13, # One of which has a 12-char name. "MaxSubClassLen" => 0, # All of which have class names of "". "SecurityLen" => 232, # One SECURITY_DESCRIPTOR is 232 bytes. "LastWrite" => "\x90mZ\cX{\xA3\xBD\cA\c@\cA" # Key was last modifed 1998/06/01 16:29:32 GMT );
With arguments, each one must be the name of a item given above. The return value is the information associated with the listed names. In other words:
return $key->Information( @names );
returns the same list as:
%info= $key->Information; return @info{@names};
The delimiter defaults to backslash ('\\'
) but is inherited from
the object used to create a new object and can be specified by an
option when a new object is created.
HKEY
handle for the associated Registry key as
an integer value. This value can then be used to Reg*() calls
from Win32API::Registry. However, it is usually easier to just
call the Win32API::Registry calls directly via:
$key->RegNotifyChangeKeyValue( ... );
For the virtual root of the local or a remote Registry,
Handle()
return "NONE"
.
$Registry->Open()
, it would reopen the same Registry key
[except in the rare case where one of the key names contains
$key->Delimiter
].
""
for local Registry keys.
KEY_*
values.
RegOpenKeyEx()
call. For Win32, this is always backslash ("\\"
).
"LMachine"
to their
associated HKEY_*
constants. Primarily for internal use and
subject to change.
tie %hash, ref($key), $key;
Since ref($key)
is the class [package] to tie the hash to and
TIEHASH()
just returns its argument, $key
, [without calling
new()
] when it sees that it is already a blessed object.
If already a reference to a tied hash [that is also an object],
it just returns itself [$ref == $ref->TiedRef
].
Mostly used internally.
ArrayValues
option and possibly
turns it on or off.
When off, Registry values fetched via a tied hash are returned as
just a value scalar [the same as GetValue()
in a scalar context].
When on, they are returned as a reference to an array containing
the value data as the [0]
element and the data type as the [1]
element.
TieValues
option and possibly
turns it on or off.
Turning this option on is not yet supported in this release of Win32::TieRegistry. In a future release, turning this option on will cause Registry values returned from a tied hash to be a tied array that you can use to modify the value in the Registry.
FastDelete
option and possibly
turns it on or off.
When on, successfully deleting a Registry key [via a tied hash]
simply returns 1
.
When off, successfully deleting a Registry key [via a tied hash and not in a void context] returns a reference to a hash that contains the values present in the key when it was deleted. This hash is just like that returned when referencing the key before it was deleted except that it is an ordinary hash, not one tied to the Win32::TieRegistry package.
Note that deleting either a Registry key or value via a tied hash in a void context prevents any overhead in trying to build an appropriate return value.
Note that deleting a Registry value via a tied hash [not in a void context] returns the value data even if <FastDelete> is on.
SplitMultis
option and possibly
turns it on or off.
If on, Registry values of type REG_MULTI_SZ
are returned as
a reference to an array of strings. See GetValue()
for more
information.
DWordsToHex
option and possibly
turns it on or off.
If on, Registry values of type REG_DWORD
are returned as a hex
string with leading "0x"
and longer than 4 characters. See
GetValue()
for more information.
FixSzNulls
option and possibly
turns it on or off.
If on, Registry values of type REG_SZ
and REG_EXPAND_SZ
have
trailing '\0'
s added before they are set and stripped before
they are returned. See GetValue()
and SetValue()
for more
information.
DualTypes
option and possibly
turns it on or off.
If on, data types are returned as a combined numeric/string value
holding both the numeric value of a REG_*
constant and the
string value of the constant's name. See GetValue()
for
more information.
DualBinVals
option and possibly
turns it on or off.
If on, Registry value data of type REG_BINARY
and no more than
4 bytes long and Registry values of type REG_DWORD
are returned
as a combined numeric/string value where the numeric value is the
``unpacked'' binary value as returned by:
hex reverse unpack( "h*", $valData )
on a ``little-endian'' computer. [Would be hex unpack("H*",$valData)
on a ``big-endian'' computer if this module is ever ported to one.]
See GetValue()
for more information.
GetOptions()
Delimiter FixSzNulls DWordsToHex ArrayValues SplitMultis DualBinVals TieValues FastDelete DualTypes
Pass in one or more of the above names (as strings) to get back an array of the corresponding current settings in the same order:
my( $fastDel, $delim )= $key->GetOptions("FastDelete","Delimiter");
Pass in no arguments to get back a reference to a hash where the above option names are the keys and the values are the corresponding current settings for each option:
my $href= $key->GetOptions(); my $delim= $href->{Delimiter};
Pass in a single reference to a hash to have the above key/value pairs added to the referenced hash. For this case, the return value is the original object so further methods can be chained after the call to GetOptions:
my %oldOpts; $key->GetOptions( \%oldOpts )->SetOptions( Delimiter => "/" );
Delimiter FixSzNulls DWordsToHex AllowLoad ArrayValues SplitMultis DualBinVals AllowSave TieValues FastDelete DualTypes
For AllowLoad
and AllowSave
, instead of the previous
setting, SetOptions
returns whether or not the change was
successful.
In a scalar context, returns only the last item. The last
option can also be specified as "ref"
or "r"
[which doesn't
need to be followed by a value] to allow chaining:
$key->SetOptions(AllowSave=>1,"ref")->RegSaveKey(...)
$ValueName
is the name of the value to add or replace and
should not have a delimiter prepended to it. Case is ignored.
$ValueType
is assumed to be REG_SZ
if it is omitted. Otherwise,
it should be one the REG_*
constants.
$ValueData
is the data to be stored in the value, probably packed
into a Perl string. Other supported formats for value data are
listed below for each possible $ValueType
.
'\0'
if it is missing. This can be
turned off by disabling the FixSzNulls
option.
$key->SetValue( "Val1\000Value2\000LastVal\000\000", "REG_MULTI_SZ" ); $key->SetValue( ["Val1","Value2","LastVal"], "REG_MULTI_SZ" );
Note that if the required two trailing nulls ("\000\000"
) are
missing, then this release of SetValue()
will not add them.
"0x"
included and totaling more than 4 bytes. These will be
packed into a 4-byte string via:
$data= pack( "L", hex($data) );
SetValue()
cannot
distinguish such from a packed string that just happens to match
a numeric value and so will treat it as a packed string.
An alternate calling format:
$okay= $key->SetValue( $ValueName, [ $ValueData, $ValueType ] );
[two arguments, the second of which is a reference to an array
containing the value data and value type] is supported to ease
using tied hashes with SetValue()
.
RegCreateKeyEx()
then, if it succeeded, creates an object
associated with the [possibly new] subkey.
$subKey
is the name of a subkey [or a path to one] to be
created or updated. It can also be a reference to an array
containing a list of subkey names.
The second argument, if it exists, should be a reference to a
hash specifying options either to be passed to RegCreateKeyEx()
or to be used when creating the associated object. The following
items are the supported keys for this options hash:
$subKey
and to be
used in the new object. Defaults to $key->Delimiter
.
KEY_*
constant values.
""
as we have never seen a use for this information.
REG_CREATED_NEW_KEY()
or REG_OPENED_EXISTING_KEY()
depending on whether a new key was created or an existing key was
opened.
If you, for example, did use Win32::TieRegistry qw(REG_CREATED_NEW_KEY)
then you can use REG_CREATED_NEW_KEY()
to compare against the numeric
value stored in the referenced scalar.
If the DualTypes
option is enabled, then in addition to the
numeric value described above, the referenced scalar will also
have a string value equal to either "REG_CREATED_NEW_KEY"
or
"REG_OPENED_EXISTING_KEY"
, as appropriate.
SECURITY_ATTRIBUTES
structure packed into a
Perl string. See Win32API::Registry::RegCreateKeyEx()
for more
information.
Volatile=>1
is the same as
specifying Options=>REG_OPTION_VOLATILE
.
Access
option is ignored. If the
calling process has enabled "SeBackupPrivilege"
, then the
subkey is opened with KEY_READ
access as the "LocalSystem"
user which should have access to all subkeys. If the calling
process has enabled "SeRestorePrivilege"
, then the subkey is
opened with KEY_WRITE
access as the "LocalSystem"
user which
should have access to all subkeys.
This option is ignored under Windows 95. Specifying Backup=>1
is the same as specifying Options=>REG_OPTION_BACKUP_RESTORE
.
RegOpenKeyEx()
call. The value
for this option should be a numeric value combining zero or more
of the REG_OPTION_*
bit masks. You may with to used the
Volatile
and/or Backup
options instead of this one.
Used to create or update a Registry key and any number of subkeys or values under it or its subkeys.
$subKey
is the name of a subkey to be created [or a path of
subkey names separated by delimiters]. If that subkey already
exists, then it is updated.
\%Contents
is a reference to a hash containing pairs of
value names with value data and/or subkey names with hash
references similar to \%Contents
. Each of these cause
a value or subkey of $subKey
to be created or updated.
If $Contents{""}
exists and is a reference to a hash, then
it used as the options argument when CreateKey()
is called
for $subKey
. This allows you to specify ...
if( defined( $$data{""} ) && "HASH" eq ref($$data{""}) ) { $self= $this->CreateKey( $subKey, delete $$data{""} );
$file
is a hive file, that is a file created by calling
RegSaveKey()
. The $file
path is interpreted relative to
%SystemRoot%/System32/config
on the machine where $key
resides.
$newSubKey
is the name to be given to the new subkey. If
$newSubKey
is specified, then $key
must be
HKEY_LOCAL_MACHINE
or HKEY_USERS
of the local computer
or a remote computer and $newSubKey
should not contain any
occurrences of either the delimiter or the OS delimiter.
If $newSubKey
is not specified, then it is as if $key
was $Registry->{LMachine}
and $newSubKey
is
"PerlTie:999"
where "999"
is actually a sequence number
incremented each time this process calls Load()
.
You can specify as the last argument a reference to a hash
containing options. You can specify the same options that you
can specify to Open()
. See Open()
for more information on
those. In addition, you can specify the option "NewSubKey"
.
The value of this option is interpreted exactly as if it was
specified as the $newSubKey
parameter and overrides the
$newSubKey
if one was specified.
The hive is automatically unloaded when the returned object
[$newKey
] is destroyed. Registry key objects opened within
the hive will keep a reference to the $newKey
object so that
it will not be destroyed before these keys are closed.
Load()
. Cannot unload other
hives. $key
must be the return from a previous call to Load()
.
$key
is closed and then the hive is unloaded.
"ReBackupPrivilege"
privilege for the
current process. You will probably have to enable this privilege
before you can use RegSaveKey()
.
The return value indicates whether the operation succeeded, not whether the privilege was previously enabled.
"ReRestorePrivilege"
privilege for the
current process. You will probably have to enable this privilege
before you can use RegLoadKey()
, RegUnLoadKey()
,
RegReplaceKey()
, or RegRestoreKey
and thus Load()
and
UnLoad()
.
The return value indicates whether the operation succeeded, not whether the privilege was previously enabled.
use
and import()
]To have nothing imported into your package, use something like:
use Win32::TieRegistry 0.20 ();
which would verify that you have at least version 0.20 but wouldn't
call import()
. The Changes file can be useful in figuring out
which, if any, prior versions of Win32::TieRegistry you want to
support in your script.
The code
use Win32::TieRegistry;
imports the variable $Registry
into your package and sets it
to be a reference to a hash tied to a copy of the master Registry
virtual root object with the default options. One disadvantage
to this ``default'' usage is that Perl does not support checking
the module version when you use it.
Alternately, you can specify a list of arguments on the use
line that will be passed to the Win32::TieRegistry->import()
method to control what items to import into your package. These
arguments fall into the following broad categories:
$scalar
into your package
(or the package named ``pack'') and then sets it.
$scalar
.
%hash
into your package
(or the package named ``pack'') and then sets it.
%hash
.
$scalar
into your package
(or the package named ``pack'') and then sets it.
$scalar
.
constant(s)
exported by Win32API::RegistryYou can also specify ":KEY_"
, ":REG_"
, and even ":HKEY_"
to
import a whole set of constants.
See Win32API::Registry documentation for more information.
SetOptions()
method call, each followed by the value to use for that option.
A Registry virtual root object is created, all of these options are
set for it, then each variable to be imported/set is associated with
this object.
In addition, the following special options are supported:
$Exporter::ExportLevel
and has the same meaning. See
the the Exporter manpage module for more information.
This module was written with a strong emphasis on the convenience of
the module user. Therefore, most places where you can specify a
constant like REG_SZ()
also allow you to specify a string
containing the name of the constant, "REG_SZ"
. This is convenient
because you may not have imported that symbolic constant.
Perl also emphasizes programmer convenience so the code REG_SZ
can be used to mean REG_SZ()
or "REG_SZ"
or be illegal.
Note that using ®_SZ
(as we've seen in much Win32 Perl code)
is not a good idea since it passes the current @_
to the
constant()
routine of the module which, at the least, can give
you a warning under -w.
Although greatly a matter of style, the ``safest'' practice is probably
to specifically list all constants in the use Win32::TieRegistry
statement, specify use strict
[or at least use strict qw(subs)
],
and use bare constant names when you want the numeric value. This will
detect misspelled constant names at compile time.
use strict; my $Registry; use Win32::TieRegistry 0.20 ( TiedRef => \$Registry, Delimiter => "/", ArrayValues => 1, SplitMultis => 1, AllowLoad => 1, qw( REG_SZ REG_EXPAND_SZ REG_DWORD REG_BINARY REG_MULTI_SZ KEY_READ KEY_WRITE KEY_ALL_ACCESS ), ); $Registry->{"LMachine/Software/FooCorp/"}= { "FooWriter/" => { "/Fonts" => [ ["Times","Courier","Lucinda"], REG_MULTI_SZ ], "/WindowSize" => [ pack("LL",24,80), REG_BINARY ], "/TaskBarIcon" => [ "0x0001", REG_DWORD ], }, } or die "Can't create Software/FooCorp/: $^E\n";
If you don't want to use strict qw(subs)
, the second safest practice
is similar to the above but use the REG_SZ()
form for constants
when possible and quoted constant names when required. Note that
qw()
is a form of quoting.
use Win32::TieRegistry 0.20 qw( TiedRef $Registry Delimiter / ArrayValues 1 SplitMultis 1 AllowLoad 1 REG_SZ REG_EXPAND_SZ REG_DWORD REG_BINARY REG_MULTI_SZ KEY_READ KEY_WRITE KEY_ALL_ACCESS ); $Registry->{"LMachine/Software/FooCorp/"}= { "FooWriter/" => { "/Fonts" => [ ["Times","Courier","Lucinda"], REG_MULTI_SZ() ], "/WindowSize" => [ pack("LL",24,80), REG_BINARY() ], "/TaskBarIcon" => [ "0x0001", REG_DWORD() ], }, } or die "Can't create Software/FooCorp/: $^E\n";
The examples in this document mostly use quoted constant names
("REG_SZ"
) since that works regardless of which constants
you imported and whether or not you have use strict
in your
script. It is not the best choice for you to use for real
scripts (vs. examples) because it is less efficient and is not
supported by most other similar modules.
Most things can be done most easily via tied hashes. Skip down to the the Tied Hashes Summary to get started quickly.
Here are quick examples that document the most common functionality of all of the method functions [except for a few almost useless ones].
# Just another way of saying Open(): $key= Win32::TieRegistry->new("LMachine\\Software\\", { Access=>KEY_READ()|KEY_WRITE(), Delimiter=>"\\" });
# Open a Registry key: $subKey= $key->Open( "SubKey/SubSubKey/", { Access=>KEY_ALL_ACCESS, Delimiter=>"/" } );
# Connect to a remote Registry key: $remKey= $Registry->Connect( "MachineName", "LMachine/", { Access=>KEY_READ, Delimiter=>"/" } );
# Get value data: $valueString= $key->GetValue("ValueName"); ( $valueString, $valueType )= $key->GetValue("ValueName");
# Get list of value names: @valueNames= $key->ValueNames;
# Get list of subkey names: @subKeyNames= $key->SubKeyNames;
# Get combined list of value names (with leading delimiters) # and subkey names (with trailing delimiters): @memberNames= $key->MemberNames;
# Get all information about a key: %keyInfo= $key->Information; # keys(%keyInfo)= qw( Class LastWrite SecurityLen # CntSubKeys MaxSubKeyLen MaxSubClassLen # CntValues MaxValNameLen MaxValDataLen );
# Get selected information about a key: ( $class, $cntSubKeys )= $key->Information( "Class", "CntSubKeys" );
# Get and/or set delimiter: $delim= $key->Delimiter; $oldDelim= $key->Delimiter( $newDelim );
# Get "path" for an open key: $path= $key->Path; # For example, "/CUser/Control Panel/Mouse/" # or "//HostName/LMachine/System/DISK/".
# Get name of machine where key is from: $mach= $key->Machine; # Will usually be "" indicating key is on local machine.
# Control different options (see main documentation for descriptions): $oldBool= $key->ArrayValues( $newBool ); $oldBool= $key->FastDelete( $newBool ); $oldBool= $key->FixSzNulls( $newBool ); $oldBool= $key->SplitMultis( $newBool ); $oldBool= $key->DWordsToHex( $newBool ); $oldBool= $key->DualBinVals( $newBool ); $oldBool= $key->DualTypes( $newBool ); @oldBools= $key->SetOptions( ArrayValues=>1, FastDelete=>1, FixSzNulls=>0, Delimiter=>"/", AllowLoad=>1, AllowSave=>1 ); @oldBools= $key->GetOptions( ArrayValues, FastDelete, FixSzNulls );
# Add or set a value: $key->SetValue( "ValueName", $valueDataString ); $key->SetValue( "ValueName", pack($format,$valueData), "REG_BINARY" );
# Add or set a key: $key->CreateKey( "SubKeyName" ); $key->CreateKey( "SubKeyName", { Access=>"KEY_ALL_ACCESS", Class=>"ClassName", Delimiter=>"/", Volatile=>1, Backup=>1 } );
# Load an off-line Registry hive file into the on-line Registry: $newKey= $Registry->Load( "C:/Path/To/Hive/FileName" ); $newKey= $key->Load( "C:/Path/To/Hive/FileName", "NewSubKeyName", { Access=>"KEY_READ" } ); # Unload a Registry hive file loaded via the Load() method: $newKey->UnLoad;
# (Dis)Allow yourself to load Registry hive files: $success= $Registry->AllowLoad( $bool );
# (Dis)Allow yourself to save a Registry key to a hive file: $success= $Registry->AllowSave( $bool );
# Save a Registry key to a new hive file: $key->RegSaveKey( "C:/Path/To/Hive/FileName", [] );
See Win32API::Registry for more information on these methods.
These methods are provided for coding convenience and are
identical to the Win32API::Registry functions except that these
don't take a handle to a Registry key, instead getting the handle
from the invoking object [$key
].
$key->RegGetKeySecurity( $iSecInfo, $sSecDesc, $lenSecDesc ); $key->RegLoadKey( $sSubKeyName, $sPathToFile ); $key->RegNotifyChangeKeyValue( $bWatchSubtree, $iNotifyFilter, $hEvent, $bAsync ); $key->RegQueryMultipleValues( $structValueEnts, $cntValueEnts, $Buffer, $lenBuffer ); $key->RegReplaceKey( $sSubKeyName, $sPathToNewFile, $sPathToBackupFile ); $key->RegRestoreKey( $sPathToFile, $iFlags ); $key->RegSetKeySecurity( $iSecInfo, $sSecDesc ); $key->RegUnLoadKey( $sSubKeyName );
For fast learners, this may be the only section you need to read. Always append one delimiter to the end of each Registry key name and prepend one delimiter to the front of each Registry value name.
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 ); $Registry->Delimiter("/"); # Set delimiter to "/". $swKey= $Registry->{"LMachine/Software/"}; $winKey= $swKey->{"Microsoft/Windows/CurrentVersion/"}; $userKey= $Registry-> {"CUser/Software/Microsoft/Windows/CurrentVersion/"}; $remoteKey= $Registry->{"//HostName/LMachine/"};
$progDir= $winKey->{"/ProgramFilesDir"}; # "C:\\Program Files" $tip21= $winKey->{"Explorer/Tips//21"}; # Text of tip #21.
$winKey->ArrayValues(1); ( $devPath, $type )= $winKey->{"/DevicePath"}; # $devPath eq "%SystemRoot%\\inf" # $type eq "REG_EXPAND_SZ" [if you have SetDualVar.pm installed] # $type == REG_EXPAND_SZ() [if did C<use Win32::TieRegistry qw(:REG_)>]
$winKey->{"Setup//SourcePath"}= "\\\\SwServer\\SwShare\\Windows"; # Simple. Assumes data type of REG_SZ.
$winKey->{"Setup//Installation Sources"}= [ "D:\x00\\\\SwServer\\SwShare\\Windows\0\0", "REG_MULTI_SZ" ]; # "\x00" and "\0" used to mark ends of each string and end of list.
$winKey->{"Setup//Installation Sources"}= [ ["D:","\\\\SwServer\\SwShare\\Windows"], "REG_MULTI_SZ" ]; # Alternate method that is easier to read.
$userKey->{"Explorer/Tips//DisplayInitialTipWindow"}= [ pack("L",0), "REG_DWORD" ]; $userKey->{"Explorer/Tips//Next"}= [ pack("S",3), "REG_BINARY" ]; $userKey->{"Explorer/Tips//Show"}= [ pack("L",0), "REG_BINARY" ];
$swKey->{"FooCorp/"}= { "FooWriter/" => { "/Version" => "4.032", "Startup/" => { "/Title" => "Foo Writer Deluxe ][", "/WindowSize" => [ pack("LL",$wid,$ht), "REG_BINARY" ], "/TaskBarIcon" => [ "0x0001", "REG_DWORD" ], }, "Compatibility/" => { "/AutoConvert" => "Always", "/Default Palette" => "Windows Colors", }, }, "/License", => "0123-9C8EF1-09-FC", };
@members= keys( %{$swKey} ); @subKeys= grep( m#^/#, keys( %{$swKey->{"Classes/batfile/"}} ) ); # @subKeys= ( "/", "/EditFlags" ); @valueNames= grep( ! m#^/#, keys( %{$swKey->{"Classes/batfile/"}} ) ); # @valueNames= ( "DefaultIcon/", "shell/", "shellex/" );
$oldValue= delete $userKey->{"Explorer/Tips//Next"};
$oldValues= delete $userKey->{"Explorer/Tips/"}; # $oldValues will be reference to hash containing deleted keys values.
undef $swKey; # Explicit way to close a key. $winKey= "Anything else"; # Implicitly closes a key. exit 0; # Implicitly closes all keys.
This module was originally called Tie::Registry. Changing code
that used Tie::Registry over to Win32::TieRegistry is trivial
as the module name should only be mentioned once, in the use
line. However, finding all of the places that used Tie::Registry
may not be completely trivial so we have included Tie/Registry.pm
which you can install to provide backward compatibility.
Tye McQueen. See http://www.metronet.com/~tye/ or e-mail tye@metronet.com with bug reports.
Win32API::Registry - Provides access to Reg*()
, HKEY_*
,
KEY_*
, REG_*
[required].
Win32::WinError - Defines ERROR_*
values [optional].
SetDualVar - For returning REG_*
values as combined
string/integer values [optional].
Because Perl hashes are case sensitive, certain lookups are also case sensitive. In particular, the root keys (``Classes'', ``CUser'', ``LMachine'', ``Users'', ``PerfData'', ``CConfig'', ``DynData'', and HKEY_*) must always be entered without changing between upper and lower case letters. Also, the special rule for matching subkey names that contain the user-selected delimiter only works if case is matched. All other key name and value name lookups should be case insensitive because the underlying Reg*() calls ignore case.
Information about each key is cached when using a tied hash. This cache is not flushed nor updated when changes are made, even when the same tied hash is used to make the changes.
Current implementations of Perl's ``global destruction'' phase can
cause objects returned by Load()
to be destroyed while keys
within the hive are still open, if the objects still exist when
the script starts to exit. When this happens, the automatic
UnLoad()
will report a failure and the hive will remain loaded
in the Registry.
Trying to Load()
a hive file that is located on a remote network
share may silently delete all data from the hive. This is a bug
in the Win32 APIs, not any Perl code or modules. This module does
not try to protect you from this bug.
There is no test suite.
The following items are desired by the author and may appear in a future release of this module.
RegNotifyChangeKeyValue()
to keep tied hash
caches up-to-date even when other programs make changes.
warn
or die
.
For complex operations, such a copying an entire subtree, provide access to detailed information about errors (and perhaps some warnings) that were encountered. Let the user control whether the complex operation continues in spite of errors.
Copyright 1999 - 2006 Tye McQueen.
Some parts copyright 2007 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Win32::TieRegistry - Manipulate the Win32 Registry |