Win32::TieRegistry

J

January Weiner

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

--
 
A

A. Sinan Unur

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
 
J

January Weiner

A. Sinan Unur said:
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.

--
 
A

A. Sinan Unur

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
 
J

January Weiner

Andreas Pürzer said:
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):

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.

--
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top