[Distutils] Installing without administrator privileges

Phil Rittenhouse Phil.Rittenhouse@dspfactory.com
Tue Aug 6 11:26:15 2002


Hi all,

I encountered the following problem when trying to install a package I had
generated
with distutils:

When the installer was run, it would go through the steps nicely, but
towards the end, it
generated two errors:
        "Could not open key
Software\Microsoft\Windows\CurrentVersion\Uninstall"
        "Could not create key  dsp-py2.1"

At first I thought the problem might be the result of installing Python as
Administrator, and the
package as just a user, so I re-installed Python as a user, but I still got
the same error.  I ran
my test on Win2K with both Python 2.1 and 2.2, and I always got the same
result.

I tracked the code generating the error to install.c in
distutils-1.0.2/misc (see below).
I did some digging and it appears that to use KEY_ALL_ACCESS, the code must
be running
with Administrator privileges.   I checked the CVS archives to see if
KEY_ALL_ACCESS is
still being used, and it hasn't been changed.

I made the following changes to install.c (from Distutils 1.0.2),
recompiled, and it  works now.

796c796
<                         KEY_CREATE_SUB_KEY,
---
>                         KEY_ALL_ACCESS,
806c806
<                           KEY_WRITE,
---
>                           KEY_ALL_ACCESS,
1177c1177
<                KEY_WRITE,
---
>                KEY_ALL_ACCESS,
1208c1208
<                KEY_WRITE,
---
>                KEY_ALL_ACCESS,


I chose KEY_CREATE_SUB_KEY for the open, since that is the only operation
that will be performed
on it.   For the new key itself, I chose KEY_WRITE, since that was also the
minimal operation.  While I
was at it, I changed the code for deleting the registry key and value to
also use the minimal KEY_WRITE.
The last two changes allowed the uninstaller to work properly when run as a
normal user.


I'm no expert on distutils or the registry, so please let me know if I've
missed something obvious.

Thanks!
Phil


------------  install.c  ------------------------
<SNIP>
  result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                 KeyName,
                 0,
                 KEY_ALL_ACCESS,
                 &hKey);

    if (result != ERROR_SUCCESS)
     MessageBox(GetFocus(), "Could not open key", KeyName, MB_OK);

    sprintf(buffer, "%s-py%d.%d", meta_name, py_major, py_minor);

    result = RegCreateKeyEx(hKey, buffer,
                   0, NULL, 0,
                   KEY_ALL_ACCESS,
                   NULL,
                   &hSubkey,
                   &disposition);

    if (result != ERROR_SUCCESS)
     MessageBox(GetFocus(), "Could not create key", buffer, MB_OK);
<SNIP>
--------------------------------------------------------------------