GnuPG and Windows Registry variables

Mark H. Wood mwood@IUPUI.Edu
Fri Sep 6 16:04:02 2002


On Wed, 4 Sep 2002, Ryan Malayter wrote:
> For some reason, Win32 ports of GnuPG 1.1.91 doesn't appear to handle
> the REG_EXPAND_SZ registry data type correctly.
>
> For example, I want to change the HKLM\Software\GNU\GnuPG\HomeDir
> setting from a static string data type to a REG_EXPAND_SZ type, with
> value "C:/Documents and Settings/%USERNAME%/Application Data/GnuPG".
> This should, in theory, allow multiple users to have individualized
> options for GnuPG on the same machine. The %USERNAME% is supposed to be
> replaced by the current user when the value is read from the registry,
> returning a customized user's Windows 2000 profile path for each user.

No, it's more complex than that.  User profiles may be located anywhere;
the form you give is only the default and may not be correct even then.
To form a path to the Application Data directory, you need to expand
%APPDATA% (if it exists on this platform).  Thus:

  %APPDATA%\GnuPG

Another approach is to ask the shell for the Application Data path and
append the product name.  Use:

  ShGetFolderPath(hwnd,CSIDL_APPDATA,NULL,SHGFP_TYPE_CURRENT,&pathbuffer)

to get the path to the Application Data directory.  The PSDK's Windows
Programming Guidelines recommend this method.  However, Application Data
was not in the original Win32 design (or they didn't get around to
implementing it for a while) so older platforms won't know what to do with
either %APPDATA% or CSIDL_APPDATA.  You need a fallback.

> I thought Windows would handle this variable replacement itself, because
> it works transparently for several other programs I use frequently.

No, it won't.  The current PSDK documentation states that one must run
REG_EXPAND_SZ data through ExpandEnvironmentStrings() to get the proper
substitutions.  The difference between REG_SZ and REG_EXPAND_SZ appears to
be only that the latter may be expanded while the former should not.  I
believe that the Registry APIs themselves use the same code paths for both
types.

-- 
Mark H. Wood, Lead System Programmer   mwood@IUPUI.Edu
MS Windows *is* user-friendly, but only for certain values of "user".