NAME

Win32::Registry - accessing the Win32 registry

Tweak version 0.00.27.


SYNOPSIS

 use Win32::Registry;
 print $HKLM->Open('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Tips')->GetValue('32');


DESCRIPTION

This module creates an object oriented interface to registry. It allows you to read&update local as well as remote registry.

Win32::Registry is -w and use strict vars safe. :-) (At least it seems to be ;-) If you find any problems, send me their description and hopefully a fix to Jenda@Krynicky.cz.

      !!! Use with caution !!! Use with caution !!! Use with caution !!!

Editing registry can easily render you computer unusable. If you step over something important --- happy reinstalling ;-]

Win32::Registry | Base objects | Methods and functions | Constants and Variables


Base objects

You may use them to ->Open or ->Create subkeys or you may Connect a remote registry.

The predefined base objects are :

$HKEY_LOCAL_MACHINE (shortcut = $HKLM)

Informations about the local computer system, including hardware and OS.

$HKEY_CLASSES_ROOT (shortcut = $HKCR)

Object linking and embedding (OLE) and file-class association data.

$HKEY_USERS (shortcut = $HKU)

All actively loaded user profiles, including HKEY_CURRENT_USER, which always refers to a child of HKEY_USERS, and the default profile.

$HKEY_CURRENT_USER (shortcut = $HKCU)

User profile for the user who is currently logged on, including environment variables, personal program groups, desktop settings, network connections, printers, and application preferences.

$HKEY_CURRENT_CONFIG

Points to the current system configuration in the collection of configurations stored in Hkey_Local_Machine\Config.

$HKEY_DYN_DATA

Handle to informations from the devices currently installed and loaded, or that failed loading. This is dynamic information, stored in volatile memory. Data are updated at startup and whenever the system configuration is modified. It also contains some performance data under under Hkey_Dyn_Data\PerfStats.

$HKEY_PERFORMANCE_DATA
$HKEY_PERFORMANCE_TEXT
$HKEY_PERFORMANCE_NLSTEXT

Handles used to collect performance data with RegQueryValueEx. Note that the performance data are not stored in the Registry database. ReqQueryKeyEx will cause the system to collect the data.

Win32::Registry | Base objects | Methods and functions | Constants and Variables


Methods and functions

Connect, Open, OpenEx, Create, Close, Num2Object

GetValue, GetType, GetValueEx, QueryValue, QueryType, QueryValueEx, GetValues, GetOnlyValues, GetKeys

DeleteKey, DeleteValue, SetValue, SetValues, SetValueEx

CopyKey, MoveKey

FlushKey, Refresh, QueryKey, QueryInfoKey, Path, Root

FindKey, FindKeyDepth, FindValue, FindValueDepth, Load, Save, Import, Export

Since tweak 0.00.20 you may call most of those methods as ordinary functions while using registry path as the first argument. Only exceptions are Close(),FlushKey().

Close

 $obj->Close

Close an open registry key. You should close keys as soon as possible to free the resources. Object that are being destroyed are automatically closed. Returns true if successful.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Connect

 $newobj = Win32::Registry::Connect( $Server [, $hkey ])
 [$newobj = ]$obj->Connect( $Server [, $newobj ])

Connects a remote registry.

If you call it as an ordinary function it connects the $hkey (NUMERICAL HANDLE!) or HKEY_LOCAL_MACHINE on that machine.

 $newobj = Win32::Registry::Connect($server, &HKEY_USERS);

Since version 0.00.05 you may use any registry object with this method. It tries to connect $obj->Root on the remote machine and then ->Open the same $obj->Path. If any of these fails you will get an undef.

Ex: $obj = Win32::Registry::Connect( $Server , HKEY_CLASSES_ROOT); $obj2 = $HKEY_USERS->Connect( $Server);

Win32::Registry | Base objects | Methods and functions | Constants and Variables

CopyKey

 $key->CopyKey($to [, $as]);
 Win32::Registry::CopyKey($key, $to [, $as]);

Copy a $key under $to, possibly with a different name. You may use this to copy a whole registry key with all subkeys into a different branch. For example from HKEY_USERS\.DEFAULT to HKEY_CURRENT_USER.

Both the $key and $to may be either paths or registry objects. The $to MUST already exist, the copy will be created UNDER this key. It will NOT overwrite it.

 Ex.:
  use Win32::Registry;
  $to = $HKCU->Create('SOFTWARE\Jenda');
  Win32::Registry::CopyKey('HKEY_USERS\.DEFAULT\SOFTWARE\Jenda\ThisScript',$to);
  
 or

  use Win32::Registry;
  $to = $HKCU->Create('SOFTWARE\Jenda');
  Win32::Registry::CopyKey('HKEY_USERS\.DEFAULT\SOFTWARE\Jenda\ThisScript\'s defaults',$to,'ThisScript');

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Create

 [ $SubKeyObj = ] $obj->Create("SubKey" [,$SubKeyObj] )
 [ $SubKeyObj = ] Win32::Registry::Create("absolute path","SubKey" [,$SubKeyObj])

Opens a subkey of a Registry object. If it doesn't exist, it gets created. The created object is returned through the second parameter and as the function result.

 Eg: $SubKeyObj=$RegObj->Create( "SubKey")
      or die "Cannot create SubKey.\n";
     $RegObj->Create( 'SubKey\SubSubKey',$SubSubKeyObj )
      or die "Cannot create SubKey.\n";
     $Jenda = Win32::Registry::Create('HKEY_LOCAL_MACHINE\SOFTWARE','Jenda');

Win32::Registry | Base objects | Methods and functions | Constants and Variables

DeleteKey

 $regobj->DeleteKey( "KeyNameToDelete" [, 1]);
 $regobj->DeleteKey();
 Win32::Registry::DeleteKey('HKEY_WHATEVER\path\to\KeyNameToDelete');
 Win32::Registry::DeleteKey('HKEY_WHATEVER\path\to' ,'KeyNameToDelete' [, 1]);

Delete a key from the registry. Returns true if successful.

The optional third parameter allows the function to delete the key recursively. That is to delete even keys that contain some subkeys.

  Eg: $HKEY_CLASSES_ROOT->DeleteKey( "MyFileType");
      Win32::Registry::DeleteKey('HKEY_CLASSES_ROOT\MyFileType');

Win32::Registry | Base objects | Methods and functions | Constants and Variables

DeleteValue

 $obj->DeleteValue($ValueName, ...);
 Win32::Registry::DeleteValue('registry path', $ValueName, ...);

Delete a value from the current key

  $reg->DeleteValue( "Name" );
  $reg->DeleteValue( "Name", "Other_Name");

Returns the number of successful deletions and sets $! in case of an error.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Export

 $obj->Export( [$filename, [$continuation]] )

Export the key into a registry script (.REG) file. This method creates a standard registry script, the same you get when you export a key from Regedit.exe.

If you do not specify the $filename, the text gets printed to the currently select()ed filehandle.

If the $continuation is defined, no header is printed out. You may use this to export several keys into one file.

If you do not want to specify the filename, but need continuation, use undef() as the $filename.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

FindKey

 $obj->FindKey(\&function [, \&leavefunction])
 $obj->FindKey(\&bool_function,\@array)

Recurses through the subkeys of $obj, similar to File::Find.

If you call this function using the first syntax, it recurses through the registry and calls &function you passed before precessing each key. If the &leavefunction is defined, it is being called AFTER processing the subkeys. The key is passed to &function (or \&leavefunction) as it's first parameter.

If you use the other form, each time the &bool_function returns true FindKey pushes the path of the active key to @array.

You may instruct the method to skip processing the subkeys of the current key by seting $Win32::Registry::Find::skip_subkeys variable to 1 in the callback function.

 Ex.
  $reg = $HKLM->Open('SOFTWARE\Microsoft\Office');

  # print out all subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office
  # and their default values
  sub prt {
   print $_[0]->Path,' = ',$_[0]->GetValue(''),"\n";
   # # or
   # my $self=shift;
   # print $self->Path,' = ',$self->GetValue(''),"\n";
  }
  $reg->FindKey(\&prt);

  # find out what subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office
  # have their default value set
  sub dft {
   return $_[0]->GetValue('');
  }
  $reg->FindKey(\&dft,\@arr);
  foreach $key (@arr) {
   print "$key has the default value set.\n"
  }

  sub ExportFoo {
    return unless $Win32::Registry::Find::path =~ /jenda/i;
    $_[0]->Export('c:\temp\Foo.reg', $continued++);
    $Win32::Registry::Find::skip_subkeys = 1;
  }
  $continued=0;
  $HKLM->FindKey(\&ExportFoo);
  
C<Win32::Registry> | C<Base objects> |  C<Methods and functions> | C<Constants and Variables>
FindKeyDepth

 $obj->FindKeyDepth(\&function)
 $obj->FindKeyDepth(\&bool_function,\@array)

Same as FindKeyDepth, but depth first.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

FindValue

 $obj->FindValue(\&function, [, \&KeyEnterFunction [, \&KeyLeaveFunction [, \&SubKeysLeaveFunction]]])

Recurses through the registry, calling &function for every value found. You may also define functions to be called when

 1. entering the key - &KeyEnterFunction
 2. finished processing the values, but before recursing into subkeys - &KeyLeaveFunction
 3. finished processing all subkeys - &SubKeysLeaveFunction

The &function get's its parameters through global variables :

 Win32::Registry::Find::key - the key in which the value resides
 Win32::Registry::Find::name - the name of the value
 Win32::Registry::Find::type - the type of the value
 Win32::Registry::Find::value - the value

If you set the $Win32::Registry::CFG{'value_objects'} variable, the &function gets a Win32::Registry::Value object as it's first parameter.

The other functions get a registry object pointing to the current key as their first and only argument. Just like in FindKey.

 Ex.
  use Win32::Registry;
  $reg = $HKLM->Open('SOFTWARE\Microsoft\Office');
  
  sub prt {
   package Win32::Registry::Find;
   if (($type = &REG_SZ or $type = &REG_MULTI_SZ)) {
    print $key->Path," \ $name = $value\n";
   }
   package main;
  }
  $reg->FindValue(\&prt);

 #======================

  $Win32::Registry::CFG{'value_objects'}=1;
  sub foo {
   my $self=shift;
   print $self->Name," : ",$RegType{$self->Type},' : ',$self->Value,"\n";
  }
  $reg->FindValue(\&foo);

 #======================

 sub FooVal {
  if ($Win32::Registry::Find::type == ::REG_BINARY) {
   print "$Win32::Registry::Find::name : ",
    "$Win23::Registry::RegType{$Win32::Registry::Find::type}",
    "($Win32::Registry::Find::type)\n";
  } else {
   print "$Win32::Registry::Find::name : ",
    "$Win23::Registry::RegType{$Win32::Registry::Find::type}",
    "($Win32::Registry::Find::type) = $Win32::Registry::Find::value\n";
  }
 }

 sub inkeyfun   { print "Entering ",$_[0]->Path,"\n"; }

 sub outkeyfun  { print "Finished printing ",$_[0]->Path,"\n"; }

 sub outsubkeys { print "Leaving ",$_[0]->Path,"\n"; }

 $reg = $HKCU->Open('Printers');
 $reg->FindValue(\&::FooVal, \&inkeyfun, \&outkeyfun, \&outsubkeys );

Win32::Registry | Base objects | Methods and functions | Constants and Variables

FindValueDepth

 $obj->FindValueDepth(\&function)

Recurses through the registry, calling &function for every value found. Depth first.

See FindValue.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

FlushKey

 $obj->FlushKey()

The FlushKey function writes all the attributes of the specified open key into the registry.

It is not necessary to call FlushKey to change a key. Registry changes are flushed to disk by the registry using its lazy flusher. Registry changes are also flushed to disk at system shutdown.

Unlike Close, the FlushKey function returns only when all the data has been written to the registry.

The FlushKey function may also write out parts of or all of the other keys. Calling this function excessively can have a negative effect on an application's performance.

An application should only call FlushKey if it requires absolute certainty that registry changes are on disk. In general, FlushKey rarely, if ever, need be used.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

ForKeys

 $obj->ForKeys(\&fun);
 $obj->ForKeys(sub{...});

Call the specified function/code for each subkey of the current key. The name of the subkey is in the first parameter to the function, the current key object is in $_.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetKeys

 $obj->GetKeys(\@ARRAY)
 @ARRAY = $obj->GetKeys()

Get the list of subkeys of current key. The list must be passed by reference!

In scalar context returns true or false, in array context returns an array of subkeys.

       foreach $key ($myobj->GetKeys()) {
        ...

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetType

Nickname for QueryType

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetValue

 $value = $obj->GetValue("value name")
 $obj->GetValue("value name",$value)

This is what Query value should be. It returns the named value from the current key, instead of the default value of the named subkey.

If you want the default value from the current key use ``'' as the name.

You should never use QueryValue, it's present only for backwards compatibility with Win3.x.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetValueEx

Nickname for QueryValueEx

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetValues

 $obj->GetValues(\%HASH)

GetValues creates a hash containing 'name'=> ( name,type,data ) for each value in the current key.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

GetOnlyValues

 $obj->GetOnlyValues(\%HASH)

Similar to GetValues, the created HASH contains only the values ($HASH{name} = ``value'').

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Import

 $obj->Import( $filename [ , \&keyfun [ , \&valuefun ]])
 Win32::Registry::Import( $filename [ , \&keyfun [ , \&valuefun ]])

Imports a registry script (.REG file) into registry. If the $obj points to a key at a remote computer, the script will be imported into that computer instead of the local registry.

The optional \&keyfun and \&valuefun parameters give you a way to control what is imported and where.

The &keyfun gets called for each registr key found in the .REG file. This function may change the key to where will be the values imported, the value it returns will be used as the name (path) of the key to save the values into. This path is relative to the $obj. If this function returns a false value, the whole key (BUT NOT SUBKEYS!!!) is ignored. That is, we skip to next key in the .REG file.

The &valuefun (if present) is called for each value imported. It's prototype is : &valuefun($name,$type,$value,$keypath,$obj) You may update the $name, $type and $value (that is $_[0],$_[1],$_[2]) if you like, but you should leave $keypath and $obj intact. If this function returns false, the value is not imported.

 Ex.
  Win32::Registry::Import('c:\temp\Some.reg');
   # import whole c:\temp\Some.reg, to the original place

  $reg = $HKLM->Connect($machinename);
  $reg->Import('c:\temp\Some.reg')
   # import whole c:\temp\Some.reg, to the original place into
   # the remote registry at $machinename

  Win32::Registry::Import('c:\temp\Some.reg', sub {$_[0] =~ /^HKEY_CLASSES_ROOT/});
   # import only the subkeys of HKCR

  Win32::Registry::Import('c:\temp\Some.reg', undef, sub($_[0] =~ /foo/));
   # import only the values whose names contain string "foo"

  Win32::Registry::Import('c:\temp\Some.reg', undef, sub($_[0] .= 'foo-'));
   # prepend all the imported values by "foo-"

  Win32::Registry::Import('c:\temp\Some.reg', sub {$_[0] =~ s/ActiveWare/ActiveState/i; $_[0];});
   # import the whole script, but change all occurences of ActiveWare in the keynames
   # to ActiveState

  Win32::Registry::Import('c:\temp\Some.reg', sub {$_[0] =~ s/ActiveWare/ActiveState/i} and $_[0]);
   # similar to previous, but imports only the keys containing "ActiveWare"

  $reg = $HKLM->Create('SOFTWARE\Microsloth');
  $reg->Import('c:\temp\Some.reg',sub {$_[0] =~ /^HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft/./i; $_[0]});
   # imports the whole script saving the keys from HKLM\SOFTWARE\Microsoft into $reg
   # (that is HKLM\SOFTWARE\Microsloth)

Win32::Registry | Base objects | Methods and functions | Constants and Variables

ImportStr

 $obj->ImportStr( $string [ , \&keyfun [ , \&valuefun ]])
 Win32::Registry::ImportStr( $string [ , \&keyfun [ , \&valuefun ]])

Imports a registry script (.REG file) into registry. Unlike Import() the first parameter is not a name of a file, but the script itself.

Otherwise it behaves exactly as Import().

 Ex.
  $reg->ImportStr(<<'*END*');
  [HKEY_CLASSES_ROOT\.pl]
  @="Perl"
  "Content Type"="text/plain"

  [HKEY_CLASSES_ROOT\Perl]
  @="Perl script"
  "EditFlags"=hex:00,00,00,00

  [HKEY_CLASSES_ROOT\Perl\Shell]
  @="Open"

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit]
  @="&Edit"
  "EditFlags"=hex:01,00,00,00

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit\Command]
  @="E:\\Soft\\PFE\\PFE32.EXE \"%1\""

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit\ddeexec]
  @="[FileOpen(\"%1\")]"

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit\ddeexec\Application]
  @="PFE32"

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit\ddeexec\ifexec]
  @="E:\\Soft\\PFE\\PFE32.EXE"

  [HKEY_CLASSES_ROOT\Perl\Shell\Edit\ddeexec\topic]
  @="Editor"

  [HKEY_CLASSES_ROOT\Perl\Shell\GUIOpen]
  @="Execute in &GUI"

  [HKEY_CLASSES_ROOT\Perl\Shell\GUIOpen\Command]
  @="E:\\Soft\\ACTIVE~1\\bin\\REMGUI~1.EXE \"%1\" %*"

  [HKEY_CLASSES_ROOT\Perl\Shell\Open]
  @="E&xecute"
  "EditFlags"=hex:01,00,00,00

  [HKEY_CLASSES_ROOT\Perl\Shell\Open\Command]
  @="E:\\Soft\\ActivePerl\\bin\\Perl.exe \"%1\" %*"

  *END*
 
 

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Load

 $reg->Load( $SubKey, $FileName [, REG_LOADTEMPORARY | REG_LOADPERSISTENT ])

The RegLoadKey function creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey. This registration information is in the form of a hive. A hive is a discrete body of keys, subkeys, and values that is rooted at the top of the registry hierarchy. A hive is backed by a .DAT file and .LOG file.

The $obj should be either HKEY_LOCAL_MACHINE or HKEY_USERS in the local or remote registry. $SubKey is the name of the key, the file will be loaded as. $FileName is the name of the .DAT file.

If you pass REG_LOADTEMPORARY as the third parameter, the hive will be automaticaly unloaded at the end of script.

You may not load parts of Win95 registry on WinNT and vice versa!

Windows NT: The owner of the calling process must have the SE_RESTORE_NAME privilege.

Windows 95: Security privileges are not supported nor required.

 Ex.
  $HKLM->Load('User','c:\winnt\profiles\user\ntuser.dat');
   # 
  $HKLM->Load('Me','c:\winnt\profiles\me\ntuser.dat', REG_LOADTEMPORARY);
   # loaded only for this script, will be Unload()ed automaticaly
   # if possible.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

UnLoad

 $obj->UnLoad($SubKey)

Unloads a part of registry previously loaded by Load (RegLoadKey). The $obj should be either HKEY_LOCAL_MACHINE or HKEY_USERS.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

MoveKey

 $key->MoveKey($to [, $as]);
 Win32::Registry::MoveKey($key, $to [, $as]);

Move a $key under $to, possibly with a different name. You may use this to move a whole registry key with all subkeys into a different branch. For example from HKEY_USERS\.DEFAULT to HKEY_CURRENT_USER.

Both the $key and $to may be either paths or registry objects. The $to MUST already exist, the key will be moved UNDER this key. It will NOT overwrite it.

 Ex.:
  use Win32::Registry;
  $to = $HKCU->Create('SOFTWARE\Jenda');
  Win32::Registry::CopyKey('HKEY_USERS\.DEFAULT\SOFTWARE\Jenda\ThisScript',$to);
  
 or

  use Win32::Registry;
  $to = $HKCU->Create('SOFTWARE\Jenda');
  Win32::Registry::CopyKey('HKEY_USERS\.DEFAULT\SOFTWARE\Jenda\ThisScript\'s defaults',$to,'ThisScript');

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Num2Object

 $object = Win32::Registry::Num2Object($handle)

Makes a new object out of a handle number. Use with care!

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Open

 [ $SubKeyObj = ] $obj->Open("SubKey" [, $SubKeyObj] )
 [ $KeyObj = ] $obj->Open("\Full\path\to\a\Key" [, $KeyObj] )

Opens a subkey of a Registry object. The created object is returned through the second parameter and as the function result.

If the first parameter starts by a backslash it is considered an absolute path from the object's root. The same holds for Create.

This function is provided for compatibility with Windows version 3.x. You should use the OpenEx method.

 Eg: $MS=$HKLM->Open( 'SOFTWARE\\Microsoft')
      or die "Cannot open Microsoft.\n";
     $MS->Open( '\\SOFTWARE\\ActiveWare',$AW )
      or die "Cannot open ActiveWare.\n";

Win32::Registry | Base objects | Methods and functions | Constants and Variables

OpenEx

 [ $SubKeyObj = ] $obj->Open("SubKey" , $Sam, [, $SubKeyObj] )
 [ $KeyObj = ] $obj->Open("\Full\path\to\a\Key", $Sam [, $KeyObj] )

Opens a subkey of a Registry object. The created object is returned through the second parameter and as the function result.

The $Sam specifies the requested access. Posible values are KEY_ALL_ACCESS Full access (read, write, delete) KEY_READ Read-only access KEY_WRITE Write-only access

If the first parameter starts by a backslash it is considered an absolute path from the object's root. The same holds for Create.

 Eg: $MS=$HKLM->OpenEx( 'SOFTWARE\\Microsoft',KEY_ALL_ACCESS)
      or die "Cannot open Microsoft.\n";
     $MS->OpenEx( '\\SOFTWARE\\ActiveWare',KEY_WRITE, $AW )
      or die "Cannot open ActiveWare.\n";

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Path

 print $obj->Path;

Returns the path to the key. The root is not included.

 Ex.
  use Win32::Registry;
  $reg=$HKEY_LOCAL_MACHINE->Open('SOFTWARE\\Microsoft');
  print "\$reg's root is ",$reg->Root," and path is ",$reg->Path,".\n";

Win32::Registry | Base objects | Methods and functions | Constants and Variables

QueryKey

 $obj->QueryKey($class, $numberofSubkeys, $numberofVals )
 ($class, $numberofSubkeys, $numberofVals) = $obj->QueryKey()

Get info about the current key. In list context returns the data. In scalar context returns just TRUE.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

QueryInfoKey

 $obj->QueryInfoKey($class, $classsz, $reserved, $numsubkeys,$maxsubkey,
                    $maxclass, $values, $maxvalname, $maxvaldata,
                    $secdesclen,$lastwritetime)
 ($class, $classsz, $reserved, $numsubkeys,$maxsubkey, $maxclass,
  $values, $maxvalname, $maxvaldata, $secdesclen,$lastwritetime) =
 $obj->QueryKey()

Get info about the current key. In list context returns the data. In scalar context returns just TRUE.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

QueryType

 $type_id = $obj->QueryType("value name")
 $obj->QueryType("value name",$type_id)

This method gets the type of a value in the current key or in some subkey.

There is a nickname GetType

Win32::Registry | Base objects | Methods and functions | Constants and Variables

QueryValue

 $value = $obj->QueryValue("subkey name")
 $obj->QueryValue("subkey name",$value)

This method gets the content of the default value in the specified subkey. It's primarily for compatibility with Win3.x (and with the original Win32::Registry).

You should use method GetValue, GetValueEx or QueryValueEx to get the values in the current key.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

QueryValueEx

 $obj->QueryValueEx("value name", $type, $value);
 ($name,$type,$value) = $obj->QueryValueEx("value name");
 $value = $obj->QueryValueEx("value name");

Similar to GetValue, but returns a value in the current keys, instead of the default value in a subkey. In list context returns a list containing the name, type and value. In scalar context returns just the value.

 Notice that you may not use
 ($name1,$type1,$value1) = $obj->QueryValueEx( "value name", $type, $value);
 If you use this function with three parameters it returns 1 in case of success

There is a nickname GetValueEx

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Refresh

 $obj->Refresh()

Used to clear the cache. Since I'm not able to ask for a single value in a key, I ask for all of them and then save them for subsequent requests.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Root

 $reg->Root

Gives the root of the key. That is HKEY_LOCAL_MACHINE, HKEY_USERS or such.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

Save

 $reg->Save( $FileName )

Saves the current key into a file. This file cannot already exist. The file will have the System, Hidden and Read-Only attributes set (before you began searching around ...:-)!

Windows NT: The calling process must have the SE_RESTORE_NAME privilege.

Windows 95: Security privileges are not supported or required.

Win32::Registry | Base objects | Methods and functions | Constants and Variables

SetValue

 $obj->SetValue($subkeyname,$type,$value);
 Win32::Registry::SetValue($keyname, $subkeyname, $type, $value);

SetValue sets the default value in a specified subkey of the current key.

 Ex.
  $reg->SetValue('Text',&REG_SZ,'Hello world.')
  $reg->SetValue('Number',&REG_DWORD,486);
  $reg->SetValue('Binary',&REG_BINARY,pack('c4',45,12,66,87));
  Win32::Registry::SetValue('HKEY_LOCAL_MACHINE\SOFTWARE\JendaTest', 'Number',&REG_DWORD,486);

Win32::Registry | Base objects | Methods and functions | Constants and Variables

SetValues

 $obj->SetValues('value name',$Type,$value [, 'other value name',$Type,$value [, ...]])
 Win32::Registry::SetValues('key name','value name',$Type,$value [, 'other value name',$Type,$value [, ...]])

SetValues sets a value or multiple values in the current key. If a value name is empty, it sets the default value of the key.

Please note the difference between SetValue and SetValues. While SetValue sets the default value of a subkey, SetValues sets a value in the current key! Run the examples (of course with a reasonable key opened in $reg so that you do not corrupt your system!) to see the difference.

Generaly you should not use SetValue at all, cause it is pretty contraintuitive. It is included only because of compatibility reasons.

The second form is equivalent to Create('key name')->SetValues( 'value name', ...).

 Ex.
  $reg->SetValues('Text',REG_SZ,'Hello world.')
  $reg->SetValues('Number', REG_DWORD, 486, 'Binary',REG_BINARY,pack('c4',45,12,66,87));
  $reg->SetValues( StrangeSyntax => REG_SZ ,'See perlop manpage');
  Win32::Registry::SetValues('HKEY_LOCAL_MACHINE\SOFTWARE\JendaTest',
    FirstName => &REG_SZ, 'Jan', LastName => REG_SZ, 'Krynicky',
    Email => REG_SZ, 'Jenda@Krynicky.cz');

Win32::Registry | Base objects | Methods and functions | Constants and Variables

SetValueEx

 $obj->SetValueEx("value name",$Reserved,$Type,$value)
 Win32::Registry::SetValues('key name',"value name",$Reserved,$Type,$value)

Sets a value in the current key or in a subkey. I don't have a clue what the $Reserved is. This function is included for compatibility with original Win32::Registry.

Win32::Registry | Base objects | Methods and functions | Constants and Variables


Constants and Variables

Types of registry values

  0 REG_NONE
   No value type.

  1 REG_SZ
   A sequence of characters representing human
   readable text. Unicode null terminated string.
   (You do not have to care for the Unicode nor
   null termination. Use ordinary perl strings.)

  2 REG_EXPAND_SZ
   An expandable data string, which is text that
   contains a variable to be replaced when called by
   an application (ex : %windir%\system\wsock32.dll).
   Unicode null terminated string.

  3 REG_BINARY
   Raw binary data. Most hardware component
   information is stored as binary data, and can be
   displayed in hexadecimal format. 

  4 REG_DWORD
   32 bits number. 
    REG_DWORD_LITTLE_ENDIAN
   Same as REG_DWORD.

  5 REG_DWORD_BIG_ENDIAN
   32 bits number but in big endian format. 
   Not commonly used.

  6 REG_LINK
   A symbolic link (unicode).

  7 REG_MULTI_SZ 
   A multiple string. Values that contain lists or
   multiple values in human readable text are usually
   this type (unicode). Entries are separated by
   NULL characters.

  8 REG_RESOURCE_LIST
   Ressource list in the ressource map.

  9 REG_FULL_RESOURCE_DESCRIPTOR
   Resource list in the hardware description

 10 REG_RESSOURCE_REQUIREMENT_MAP
   Resource list in the hardware description.
%RegType

Maps the registry data type codes to their human readable names.

 Ex.
  $reg=$HKEY_LOCAL_MACHINE->Open('SOFTWARE\ActiveWare\Perl5');
  ($name,$type,$value) = $reg->GetValueEx('BIN');
  print "$name : $RegType{$type} : $value\n";
$CFG

This hash is used to store the configuration of Win32::Registry module. You may use it to change the behaviour of some functions.

 $CFG{'value_objects'}

This value affects the FindValue* methods. If it is set, FindValue* creates Win32::Registry::Value objects for the values found and passes them to the function. (See FindValue.)

By default not defined.

 $CFG{'canonpath'}

This value controls the behaviour of Open() and Create() function. If it is set (default) the module processes the paths the same way directory paths are being processed. That is '.' means current directory, ooops key, '..' the key one step to root and '\' is the root (HKEY_LOCAL_MACHINE etc).

This means that you may for example write this :

 $reg->Open('..');
or
 $dot->Open('..\.doc');


NOTES

For performance reasons the module was split into three pieces. Win32/Registry.pm, Win32/Registry/Find.pm and Win32/Registry/IO.pm.

The two ``submodules'' are loaded only if necessary. This confuses pl2exe and perl2exe! If you intend to ``compile'' the script, you should explicitly use them if you are gonna use any Find* or Save/Load/Unload/Import/Export. Please keep in mind that Import and Export use some Find* functions!

 use Win32::Registry;
 use Win32::Registry::Find;
 use Win32::Registry::IO;
 
should fix all problems.

Sorry for the inconvenience.


AUTHOR

Jan Krynicky <Jenda@Krynicky.cz> & someone from ActiveState/ActiveWare/Hip Comunications

This module is based on the original Win32::Registry.pm from ActiveWare Perl 3xx. I've rewriten almost everything during time. It still uses the C/XS code, by ActiveWare, later cleared and repackaged into libwin32 by GSAR <gsar@activestate.com>

I try to support both the Perl 3xx and never perls using libwin32 and hide the differences.


COPYRIGHT

Copyright (c) 1997-1999 Jan Krynicky <Jenda@Krynicky.cz> All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.