Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Win32::TieRegistry

Reply
Thread Tools

Win32::TieRegistry

 
 
January Weiner
Guest
Posts: n/a
 
      03-03-2006
Hello,

I am writing a program which I would like to distribute both for Unix-like
and Windows platforms. In Unix, the program reads a global configuration
from /etc/programnamerc, and from the user configuration file
~/.programnamerc. I don't care about the global configuration, but the
user should be able to save hers or his configuration in Windows, too.

As far as I understand it (maybe I'm wrong?) I cannot be sure about a thing
like $HOME. I could theoretically save the user configuration at the same
place as where the program sits; however, I specifically created the
program in such a way that the single binary is everything that is needed
to run it, so that it can be easily moved around.

I thought that I might use the Win32::TieRegistry module. I have read its
documentation. However, I am quite ignorant about Windows, and I am afraid
that tampering the registry without understanding how exactly it works
might break things. Are you aware of any tutorial / faq / explanation how
to do such a basic thing as store a couple of user preferences using perl
and win32::TieRegistry?

cheers,
January

--
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-03-2006
January Weiner <(E-Mail Removed)> wrote in
news:du9e7t$4ri$(E-Mail Removed)-muenster.de:

> I am writing a program which I would like to distribute both for
> Unix-like and Windows platforms. In Unix, the program reads a global
> configuration from /etc/programnamerc, and from the user configuration
> file ~/.programnamerc. I don't care about the global configuration,
> but the user should be able to save hers or his configuration in
> Windows, too.
>
> As far as I understand it (maybe I'm wrong?) I cannot be sure about a
> thing like $HOME. I could theoretically save the user configuration
> at the same place as where the program sits; however, I specifically
> created the program in such a way that the single binary is everything
> that is needed to run it, so that it can be easily moved around.
>
> I thought that I might use the Win32::TieRegistry module. I have read
> its documentation. However, I am quite ignorant about Windows, and I
> am afraid that tampering the registry without understanding how
> exactly it works might break things. Are you aware of any tutorial /
> faq / explanation how to do such a basic thing as store a couple of
> user preferences using perl and win32::TieRegistry?


THe information you are seeking is not Perl or Win32::TieRegistry
specific. You might want to visit MSDN for that.

However, you don't need the registry to do what you want. I would
recommend the following:

1. Check if $ENV{HOME} is defined. If it is, use that directory.

2. If not, check if $ENV{APPDATA} and $ENV{USERNAME} are defined. If it
is, then create an application and user specific directory under that
path: Such as

$ENV{APPDATA}\myapp\$ENV{USERNAME}

and save the settings there

3. If both of the above fail (very unlikely on recent systems, but still
possible), ask the user where the configuration file should be placed.
Or, just create a user specific subdirectory in the program directory.
Place the config file there.

Such a scheme ought to be usable.

If you do want to go the registry route, you want to use

HKEY_CURRENT_USER -> Software -> myapp

HTH.

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
 
January Weiner
Guest
Posts: n/a
 
      03-03-2006
A. Sinan Unur <(E-Mail Removed)> wrote:
> However, you don't need the registry to do what you want. I would
> recommend the following:


> 1. Check if $ENV{HOME} is defined. If it is, use that directory.


> 2. If not, check if $ENV{APPDATA} and $ENV{USERNAME} are defined. If it
> is, then create an application and user specific directory under that
> path: Such as


> $ENV{APPDATA}\myapp\$ENV{USERNAME}


Thanks! Just one quick question. On a Windows system I can access, this
variable shows a path that includes already my username; that is, it shows
the path to my personal APPDATA. This is not standard by any chance?

> and save the settings there


> 3. If both of the above fail (very unlikely on recent systems, but still
> possible), ask the user where the configuration file should be placed.
> Or, just create a user specific subdirectory in the program directory.


OK, thanks for your answer! I would really prefer this way, as I can then
directly use the subroutines I have already written.

j.

--
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-03-2006
January Weiner <(E-Mail Removed)> wrote in
news:du9haj$4ri$(E-Mail Removed)-muenster.de:

> A. Sinan Unur <(E-Mail Removed)> wrote:
>> However, you don't need the registry to do what you want. I would
>> recommend the following:

>
>> 1. Check if $ENV{HOME} is defined. If it is, use that directory.

>
>> 2. If not, check if $ENV{APPDATA} and $ENV{USERNAME} are defined. If
>> it is, then create an application and user specific directory under
>> that path: Such as

>
>> $ENV{APPDATA}\myapp\$ENV{USERNAME}

>
> Thanks! Just one quick question. On a Windows system I can access,
> this variable shows a path that includes already my username; that is,
> it shows the path to my personal APPDATA. This is not standard by any
> chance?


There may be Win98 or ME systems where $ENV{APPDATA} is not user specific.
I don't know if $NEV{USERNAME} works on those systems, though.

HTH.

Sinan
 
Reply With Quote
 
Andreas Pürzer
Guest
Posts: n/a
 
      03-03-2006
A. Sinan Unur schrieb:
> January Weiner <(E-Mail Removed)> wrote in
> news:du9haj$4ri$(E-Mail Removed)-muenster.de:
>
>
>>A. Sinan Unur <(E-Mail Removed)> wrote:
>>
>>>However, you don't need the registry to do what you want. I would
>>>recommend the following:

>>
>>>1. Check if $ENV{HOME} is defined. If it is, use that directory.

>>
>>>2. If not, check if $ENV{APPDATA} and $ENV{USERNAME} are defined. If
>>>it is, then create an application and user specific directory under
>>>that path: Such as

>>
>>>$ENV{APPDATA}\myapp\$ENV{USERNAME}

>>


I think that $ENV{'USERPROFILE'} is also worth checking.
But please let me recommend yet another way (if the module dependency is ok with
the OP):

http://search.cpan.org/~adamk/File-H...ile/HomeDir.pm

gives you a very simple yet reliable way to cope with $HOME-related tasks.

HTH,
Andreas Pürzer

--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
 
Reply With Quote
 
January Weiner
Guest
Posts: n/a
 
      03-06-2006
Andreas Pürzer <(E-Mail Removed)> wrote:
> I think that $ENV{'USERPROFILE'} is also worth checking.
> But please let me recommend yet another way (if the module dependency is ok with
> the OP):


> http://search.cpan.org/~adamk/File-H...ile/HomeDir.pm


> gives you a very simple yet reliable way to cope with $HOME-related tasks.


Great! This one is perfect. I do not have to care about the intricates of
a Windows system myself.

j.

--
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments