Include data in a perl program?

  • Thread starter David O in Seattle
  • Start date
D

David O in Seattle

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.
 
B

Ben Morrow

David O in Seattle said:
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
 
D

David O in Seattle

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.
 
T

Thomas Kratz

David said:
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
 
D

davido

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.
 
D

davido

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;
 
B

Ben Morrow

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
 
D

davido

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

{
local $/; # by default set to undef


}

Oh cool! Thanks for that tip!
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.
 
D

davido

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*
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top