This module provides access to the Windows Registry, the database that stores information about all parts of your system and software. Many operating-system and application behaviors are controlled by Registry data. The Win32::Registry module gives you a way to access and update registry information with Perl.
WARNING: Always be careful when making changes to the registry. If vital system information gets changed by mistake, your system could become inoperable. Always make certain you have a backup of your registry before you start making modifications.
The Registry module automatically creates objects for the top-level registry trees. These objects are created in the main:: namespace, and each key that you open or create is accessed via one of these root objects. The top-level objects are:
$HKEY_CLASSES_ROOT $HKEY_CURRENT_USER $HKEY_LOCAL_MACHINE $HKEY_USERS $HKEY_PERFORMANCE_DATA $HKEY_CURRENT_CONFIG $HKEY_DYN_DATA
If you are outside of the main (default) namespace, you should package declare the keys, e.g., $main::HKEY_USERS.
use Win32::Registry; $p = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"; $HKEY_LOCAL_MACHINE->Open($p, $CurrVer) || die "Open $!";
This example creates a key object $CurrVer for the CurrentVersion key for Windows NT. This key contains several values for the current version of the operating system. With the new key open, you can read or change the values it contains (every key has at least one unnamed, default value), or open and create subkeys. The Open method can create key objects only for existing keys.
Registry values are represented in Win32::Registry functions by three elements: the name of the value, the data type of the value, and the value itself. There are several different data types for the values. Win32::Registry defines the following constants for these types:
22.15.1. Win32::Registry Methods
The following methods can be used on key objects, either on the preopened main keys or subkeys that you have already opened.
Creates a new key identified by name and saves it as the object reference named by $newkey. If the key already exists, this function simply opens the key. New keys can only be created one level below the key on which Create is used.
Returns the values contained in the current key to the hash referenced by hashref. Each registry value name is a hash key, while the hash value is a reference to a three-element list containing the name of the value, the data type, and the value.
Opens a registry key named in keyname and saves it as the object reference named by $key. keyname is the name of a key relative to the object on which Open is used ($parent).
$key->QueryKey($class, $subs, $vals)
Retrieves information about the current key and returns it to the named scalar variables. The key class is saved in the class variable (it will be the null string "" on Win95 since it doesn't use key classes). The number of subkeys is saved in the $subs variable, and the number of values in the current key is saved in $vals.
$key->SetValue(subkey, type, value)
$key->SetValueEx(name, res, type, value)
Copyright © 2002 O'Reilly & Associates. All rights reserved.