Include data in a perl program?

Discussion in 'Perl Misc' started by David O in Seattle, Feb 9, 2004.

  1. Hi,

    I'm not sure out to do this, and Google searches didn't seem to yield
    well for me (perhaps I used the wrong terms) so I thought I'd see if
    someone can point me in the right direction.

    I'm writing a PERL script to use the Win32::TieRegistry module and
    Win32API::Registry module. I noticed in Registry that there are calls
    to load registry hive data into a module. What I would LIKE to do is
    include that hive data in a scalar or similar object for use by the
    "RegLoadKey" call so I don't have to include a separate .reg file when
    I distribute my code.

    Suggestions/Guidence would be very appreciated.. TIA.
     
    David O in Seattle, Feb 9, 2004
    #1
    1. Advertising

  2. David O in Seattle

    Ben Morrow Guest

    David O in Seattle <> wrote:
    > I'm writing a PERL


    Perl or perl.

    > script to use the Win32::TieRegistry module and
    > Win32API::Registry module. I noticed in Registry that there are calls
    > to load registry hive data into a module. What I would LIKE to do is
    > include that hive data in a scalar or similar object for use by the
    > "RegLoadKey" call so I don't have to include a separate .reg file when
    > I distribute my code.


    If you can load a .reg file from a filehandle, then you can include
    the file at the end of your module after a __DATA__ token. This will
    then be available as the DATA filehandle. See perldoc perldata.

    If you can't, you want to do the same thing but write some code to
    parse the .reg format yourself: it's pretty simply :).

    Ben

    --
    "The Earth is degenerating these days. Bribery and corruption abound.
    Children no longer mind their parents, every man wants to write a book,
    and it is evident that the end of the world is fast approaching."
    -Assyrian stone tablet, c.2800 BC
     
    Ben Morrow, Feb 9, 2004
    #2
    1. Advertising

  3. On Mon, 9 Feb 2004 22:31:36 +0000 (UTC), Ben Morrow
    <> wrote:

    >
    >David O in Seattle <> wrote:
    >> I'm writing a PERL

    >
    >Perl or perl.


    Umm.. ok...


    >
    >If you can't, you want to do the same thing but write some code to
    >parse the .reg format yourself: it's pretty simply :).
    >
    >Ben


    Turns out the file that's created by the Perl modules is a binary
    "save" file and not the text-based 'reg' export file. So to use the
    text file, I'd have to write the code to insert every key. While
    that's certainly doable, I'm under a bit of a time contraint.

    Thanks tho. I appreciate your input.
     
    David O in Seattle, Feb 10, 2004
    #3
  4. David O in Seattle

    Thomas Kratz Guest

    David O in Seattle wrote:
    > Hi,
    >
    > I'm not sure out to do this, and Google searches didn't seem to yield
    > well for me (perhaps I used the wrong terms) so I thought I'd see if
    > someone can point me in the right direction.
    >
    > I'm writing a PERL script to use the Win32::TieRegistry module and
    > Win32API::Registry module. I noticed in Registry that there are calls
    > to load registry hive data into a module. What I would LIKE to do is
    > include that hive data in a scalar or similar object for use by the
    > "RegLoadKey" call so I don't have to include a separate .reg file when
    > I distribute my code.
    >
    > Suggestions/Guidence would be very appreciated.. TIA.
    >


    What about using Data::Dumper to dump a complete Win32::TieRegistry tree
    to text and store that below the __DATA__ token? Later you can eval the
    text data back to a hash and feed it again to Win32::TieRegistry.
    Perhaps you'll have to set a few of the Win32::TieRegistry options like
    'ArrayValues' or 'DualBinVals' to get a true 1:1 save nad restore.
    I haven't tested it myself, but it should be possible.

    Thomas

    --
    open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
    STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
    print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
    &&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
     
    Thomas Kratz, Feb 11, 2004
    #4
  5. David O in Seattle

    Guest

    On Wed, 11 Feb 2004 17:20:18 +0100, Thomas Kratz
    <> wrote:

    >What about using Data::Dumper to dump a complete Win32::TieRegistry tree
    >to text and store that below the __DATA__ token? Later you can eval the
    >text data back to a hash and feed it again to Win32::TieRegistry.


    I'll look into that. Thanks for the suggestion.
     
    , Feb 11, 2004
    #5
  6. David O in Seattle

    Guest

    On Wed, 11 Feb 2004 17:20:18 +0100, Thomas Kratz
    <> wrote:

    >What about using Data::Dumper to dump a complete Win32::TieRegistry tree
    >to text and store that below the __DATA__ token? Later you can eval the
    >text data back to a hash and feed it again to Win32::TieRegistry.
    >Perhaps you'll have to set a few of the Win32::TieRegistry options like
    >'ArrayValues' or 'DualBinVals' to get a true 1:1 save nad restore.
    >I haven't tested it myself, but it should be possible.



    Well, so far I keep running into the same problem. I get my hash
    reference and all that gets written to the registy is a 'text'
    representation of the TieRegistry data. Any other ideas would be
    appreciated...

    Example: Win32::TieRegistry=HASH(0x207d420)


    Code:
    my %filetypes;
    my $hashref;

    $Registry->Delimiter("/");
    $Registry->AllowLoad(1);
    $Registry->ArrayValues(1);

    my $eol = undef $/;
    eval <DATA>;

    $Registry->{"CUser/Software/VanDyke/SecureFX/File
    Types"}=\%filetypes
    or die "Can't set the File Types: $^E\n";
    $/ = $eol;
     
    , Feb 12, 2004
    #6
  7. David O in Seattle

    Ben Morrow Guest

    "" <> wrote:
    >
    > Well, so far I keep running into the same problem. I get my hash
    > reference and all that gets written to the registy is a 'text'
    > representation of the TieRegistry data. Any other ideas would be
    > appreciated...
    >
    > Example: Win32::TieRegistry=HASH(0x207d420)
    >
    >
    > Code:
    > my $eol = undef $/;


    Let Perl remember the old value for you. It's much more reliable.

    {
    local $/; # by default set to undef

    > eval <DATA>;


    }

    >
    > $Registry->{"CUser/Software/VanDyke/SecureFX/File
    > Types"}=\%filetypes
    > or die "Can't set the File Types: $^E\n";


    Try
    $Registry->{...}{$_} = $filetypes{$_}
    for keys %filetypes;

    If %filetypes is a deep structure, then you'll probably have to
    recurse over it: it looks like the tied hash stringifies everything,
    so references will be destroyed.

    Alternatively, you could take your binary dump that you had before and
    Base64 encode it. Stick that at the end of your module, then load it
    from DATA, decode it and use TieRegistry's load function (with
    IO::Scalar if necessary).

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
     
    Ben Morrow, Feb 12, 2004
    #7
  8. David O in Seattle

    Guest

    On Thu, 12 Feb 2004 23:18:29 +0000 (UTC), Ben Morrow
    <> wrote:

    >
    >"" <> wrote:
    >>
    >> Well, so far I keep running into the same problem. I get my hash
    >> reference and all that gets written to the registy is a 'text'
    >> representation of the TieRegistry data. Any other ideas would be
    >> appreciated...
    >>
    >> Example: Win32::TieRegistry=HASH(0x207d420)
    >>
    >>
    >> Code:
    >> my $eol = undef $/;

    >
    >Let Perl remember the old value for you. It's much more reliable.
    >
    > {
    > local $/; # by default set to undef
    >
    >> eval <DATA>;

    >
    > }
    >


    Oh cool! Thanks for that tip!

    >>
    >> $Registry->{"CUser/Software/VanDyke/SecureFX/File
    >> Types"}=\%filetypes
    >> or die "Can't set the File Types: $^E\n";

    >
    >Try
    > $Registry->{...}{$_} = $filetypes{$_}
    > for keys %filetypes;
    >
    >If %filetypes is a deep structure, then you'll probably have to
    >recurse over it: it looks like the tied hash stringifies everything,
    >so references will be destroyed.



    Er... You might have something there... He's a sample:

    %filetypes = bless( (
    'Access.Fragment/' => bless( {
    '/Default Icon Path' => '',
    '/Default Icon Index' => '0x00000000',
    '/Application' => '',
    '/Extensions' => '',
    '/Transfer Type' => '0x00000002',
    '/Remote File Open Action' => '0x00000001'
    }, 'Win32::TieRegistry' )
    ),'Win32::TieRegistry' );

    >
    >Alternatively, you could take your binary dump that you had before and
    >Base64 encode it. Stick that at the end of your module, then load it
    >from DATA, decode it and use TieRegistry's load function (with
    >IO::Scalar if necessary).
    >


    I like this idea better. Would the MIME::Base64 module be the one I'd
    use to encode the original binary file?

    It's looking like I might end up just 'punting' and including the SAV
    file has a binary - tho I'd rather *not* since that creates another
    distributable that needs to be managed...

    Ben/Thomas - I just wanted to say thank you for your help thus far.
    While this is a deliverable that I have to finish, you guys have
    helped me learn some cool stuff and I appreciate that.
     
    , Feb 13, 2004
    #8
  9. David O in Seattle

    Guest

    In the spirit of "There's more than one way to do it." I decided to
    find another way, and I did.

    In WinXP/Win2k3 (the platforms this tool is targeted for) there is a
    command-line version of RegEdit - simply called REG. It does the work
    for me and I just pass a call to it from my perl script. The registry
    data itself is in a __DATA__ block that I write to a temporary file
    and then use for the REG IMPORT command.

    Another problem solved. Thank you for taking the time to help me tho!

    *returns to lurk and interject mode*
     
    , Feb 13, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny Anderson
    Replies:
    5
    Views:
    517
    Victor Bazarov
    Aug 15, 2003
  2. Andreas Bogenberger
    Replies:
    3
    Views:
    959
    Andreas Bogenberger
    Feb 22, 2008
  3. Henry Law
    Replies:
    3
    Views:
    983
    Henry Law
    Jul 22, 2004
  4. Alythh

    include external perl program

    Alythh, Mar 8, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    139
    Tad McClellan
    Mar 9, 2005
  5. me
    Replies:
    10
    Views:
    986
    ccc31807
    Mar 26, 2010
Loading...

Share This Page