Langa-
        I hope you don't mind, but I'm going to copy my answer to the list
because I don't know who else out there might benefit from this information.

Everyone else-
        Keep in mind, this is Win32::TieRegistry the way _I_ understand it.
If I am wrong in any way, don't get mad, correct me.  I'd much rather be
corrected now than some other place down the road.  That being said, here's
a slightly more detailed explanation of how to use Win32::TieRegistry.  This
may be easier to read if you paste it into an editor that has syntax
highlighting, everything from the #'s on down.


############################################################


use strict; #always a good idea
use Win32::TieRegistry(Delimiter => "/");#So that we can use forward slashes

#A new Win32::TieRegistry object is automatically created
#called $Registry.  $Registry is a hash reference[1].  Each
#key of the hash it points to is either another reference to 
#another hash or a scalar which corresponds to a "value"(to
#use the Win32 registry term).  This will make a little more
#sense after you've used it a while.

#Now that we've created the registry hashes, let's try
#working with what we've created.  We can create a new
#object[1] that points to a specific part of the registry
#or we can just shoot for the part we want to change.
#For the purposes of making this easier to read, I'll make
#a new object.

my $IEKey = $Registry->{'HKEY_CURRENT_USER/Software/Microsoft/Internet
Explorer/Main/'};

#The arrow operator, the way it is used in this example, denotes that we are
#working with a hash reference, and not a key of %Registry.  We now have
#an object that represents the exact key we want to work with.  Now let's
#change the 'Start Page' value.  

$IEKey->{'Start Page'} = "http://www.perl.org";;

#Viola!  Your start page has changed.  Now let's try creating a new key.

$Registry->{'HKEY_CURRENT_USER/Software/Perl Beginners/'} = {};

#We've created a new, empty key.  Now let's set the default value.

$Registry->{'HKEY_CURRENT_USER/Software/Perl Beginners//'} = "Camel";

#Notice that since the default value does not have a name, there
#are TWO backslashes at the end of the key.  With Win32::TieRegistry,
#If you want to resolve ambiguities about whether the item at the end
#is a registry key or registry value, you can (a)add a slash to the end
#to denote a key, or (b)add two slashes before the value, so our
#double-slash denotes a value with a zero-length name[2].

#For our next trick, lets create a new object for simplicity, and add
#a value to our new key.

my $BeginnerKey = $Registry->{'HKEY_CURRENT_USER/Software/Perl Beginners/'};
$BeginnerKey->{'TIMTOWTDI'} = "There Is More Than One Way To Do It";

#And for a variation on a theme, lets try a REG_DWORD value.  This changes
#things a little because it is a binary value.  We will have to specify
#both the value and the type like so, to avoid accidentally creating
#a string value.

$BeginnerKey->{'MyDWORD'} = ['0x0001',REG_DWORD];

#Finally, let's look at reading values.  We are still treating each
#key as a hash reference, so we will have to dereference our hash to
#get the value.

my $KeyValue = $BeginnerKey->{'TIMTOWTDI'};
print "My new variable's value is:  $KeyValue\n\n";

#That looks pretty clean, but what about getting all of the keys?
#If we dereference the hash, we can use the keys() function.

my @KeyArray = keys %{$BeginnerKey};
print "Here are the values in my registry key:\n";
foreach(@KeyArray){
        if($_ eq '/'){
                print "   /(default)\n";
        }else{
                print "   $_\n";
        }
}

#There are more things you can do with this module, but I think that
#covers the basics.  If you have any questions or comments, please post
#them back to the list and I'll try to answer them if I can.

#[1]Technically $Registry is a Win32::TieRegistry object.  It is a tied
#   hash that allows you to manipulate the hash and automagically
#   cause changes to be made to the registry at the same time as changes
#   are made to the hash.  Just think of it as a hash reference if that
#   seems confusing.
#[2]Win32::TieRegistry will cut you a little slack when it comes to
#   calling keys and values, but it is always a good idea to add a slash
#   to the end whenever you are working with a key.  This reduces the
#   possibility of accidentally creating a value when you meant to create
#   a key, or vice versa.
#[3]Here's a link to a web page made from the POD documentation:
#
<http://aspn.activestate.com/ASPN/CodeDoc/libwin32/TieRegistry/TieRegistry.h
tml>

-----Original Message-----
From: Langa Kentane [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 22, 2002 8:13 AM
To: Timothy Johnson
Subject: RE: Writing to the Windows registry
Importance: Low


Hi Timothy,
Sorry to bug you but I am new to Perl and getting a little confused at this
point. What I want to do is set the IE start page using Perl for instance so
I would need to write http://someserver.domain.com/ to
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main], could you
perhaps give me an example of how I would do this.

Thanks in advance.

Langa


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to