Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I have search here for an example where I can add/modify a win32 registry keys/values, but unfortunatly I only found one short example, however I couldn't progress with it!

My problem is, I have a script that installs an application. But the install process creates 2 registry keys where the values point to the C: drive. I need to modify these values to point to the U:\ drive instead like so:
HKEY_LOCAL_MACHINE\SOFTWARE\FactSet\File Locations - "FactSetDir"="U: +\\Factset" HKEY_CURRENT_USER\Software\FactSet\File Locations - "FactSetDir"="U:\\ +Factset"
I am not sure how to progress with this since I have never used Win32::TieRegistry module before, so I wouldn't know where to start from. Your highly appreciated help and snip of code will set me up on the road for Registry propgramming in a massive way.

Thanks in advance and high regards.

Replies are listed 'Best First'.
Re: Adding Registry Keys & Values
by pg (Canon) on Nov 10, 2004 at 19:24 UTC

    Take a look at Win32::TieRegistry. This example creates foo, and set its value to bar. This same syntax is also good for modification: Change bar to whatever you want, and run the script again, you should see the value change.

    use Win32::TieRegistry; $registry = Win32::TieRegistry->new("CUser"); $registry->SetValue("foo", "bar");

    This sets a new value under HKEY_CURRENT_USER/AppEvents:

    use Win32::TieRegistry; $registry = Win32::TieRegistry->new("CUser/AppEvents", {Delimiter => " +/"}); $registry->SetValue("foo", "something");

    This creates a new key (or a path if you want to call it this way):

    use Win32::TieRegistry; $registry = Win32::TieRegistry->new("CUser", {Delimiter => "/"}); $registry->CreateKey("foo");

      And now for something completely the same using a different module. (Win32::Registry > 0.07 or Win32::Registry <= 0.07 plus the patch)

      use Win32::Registry; $HKCU->SetValues( "foo", REG_SZ, "bar"); $HKCU->Open("AppEvents")->SetValues( "foo", REG_SZ, "something"); #or #Win32::Registry::SetValues( 'HKEY_CURRENT_USER\AppEvents', # "foo", REG_SZ, "something"); $HKCU->Create("foo");

      Jenda
      We'd like to help you learn to help yourself
      Look around you, all you see are sympathetic eyes
      Stroll around the grounds until you feel at home
         -- P. Simon in Mrs. Robinson

        Thanks very much Jenda, But I had a bit of a slap rist here once for using Win32::Registry for being obselete.

        Thanks indeed.

      I'd do it like this:

      use strict; use Win32::TieRegistry qw( $registry Delimiter / ); $registry->{"CUser/AppEvents//foo"}= "something";

      As for

      I have never used Win32::TieRegistry module before, so I wouldn't know where to start from.

      I'd think you'd start by reading the documentation for Win32::TieRegistry which is fairly complete and includes lots of "quick start" material.

      - tye        

        I forgot to say "its a remote registry"!

        So my question now is how do I do the same if its a remote PC?

        Ah,..The Win32::TieRegistry documents.

        Thanks very much Tye,..can I call you Tye?