PEP proposal for user.py (win32 part)

Alan Klietz alank at NOSPAM.com
Mon Jan 21 18:58:38 EST 2002


This is wrong.  The Personal folder (CSIDL_PERSONAL) and the HOMEPATH are
two entirely distinct concepts on Windows.

On NT the Personal folder by default is kept with the *roaming* user profile
data, i.e., stuff that should move from computer to computer as you move
around the domain.  The default value under NT is %USERPROFILE%\Personal,
e.g., C:\WINNT\Profiles\alan\Personal.  It is entirely distinct from
HOMEDRIVE/HOMESHARE/HOMEPATH.  The latter is for documents that should stay
on the file server.

HOMEDRIVE/HOMESHARE/HOMEPATH come from the the password database (the SAM).
They are set with the "Home Folder" property in User Manager (on W2K MSC
under "Users and Groups").

Unfortunately the default is pretty stupid, HOMEDRIVE=C: and HOMEPATH=\.
When HOMEPATH is set to something else you can assume the systadmin pointed
it to a real home folder (*not* the Personal folder).

Unfortunately a lot of people confuse Personal and HOMEx.  The Internet
Explorer development made the infamous mistake of storing cached web pages
under the former, so every time you roamed to another computer you had to
wait for 200MB of cached web pages to be copied over to your new location.

On W2K the default Personal folder changed to "%USERPROFILE%\My Documents",
where %USERPROFILE% is now "C:\Documents and Settings\Alan".  But the stupid
default for HOMEDRIVE/HOMEPATH didn't change.

The Personal folder doesn't roam on Win98 (but not Win95) so the confusion
isn't as harmful.  (Neither one exists on Win95).

-Alan

P.S. You should never dig into the registry for the Personal folder.  It
varies depending on Terminal Server and I think some XP weirdness.  You have
to use SHGetSpecialFolderLocation(CSIDL_PERSONAL), available on all versions
of Windows except Win95 w/o MSIE.

And I assume you meant HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE.  The
latter returns the Personal folder only for Administrator.


"Gillou" <nospam at bigfoot.com> wrote in message
news:a2hglj$v6b$1 at norfair.nerim.net...
> Hi community,
>
> The actual detection for the ".pythonrc.py" file does not work with
Windows
> 95/98 and perhaps others (ME ?) because the environment variables HOMEPATH
> and HOMEDRIVE are unset by default.
> Im my Win2K box, HOMEPATH is '\' and HOMEDRIVE is 'C:'. Combination of
both
> don't give the user "HOME" directory for Windows.
>
> This replacement proposal will find the personal user folder (typically
> "...\My Documents") in the Windows registry.
>
> Replace the code beween...
>
> elif os.name == 'nt':  # Contributed by Jeff Bauer
>
> ...and...
>
> pythonrc = os.path.join(home, ".pythonrc.py")
>
> ...by the (indented) following ...
>
> import _winreg
> shellkeyId =
'Software\\Microsoft\\Windows\\CurrentVersion\\explorer\\Shell
> Folders'
> shellkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, shellkeyId)
> home = _winreg.QueryValueEx(shellkey, 'Personal')[0]
> _winreg.CloseKey(shellkey)
>
> This has been successfully tested with Windows 98se, Windows 2000 pro and
> Python 2.1.2.
> Can you please reply in this thread if this works on other Win32 platforms
> (95/ME/NT/XP).
> Any other comment ?
>
> --Gillou
>
>
>





More information about the Python-list mailing list