[Python-Dev] ntpath r54364

Christian Heimes lists at cheimes.de
Thu Jan 17 21:43:39 CET 2008


Tim Golden wrote:
> Frustratingly, I don't believe there's *any* canonical
> way to find ~user without actually going through the whole
> process of getting a token and impersonating them. If
> they've logged onto this machine already you can have
> a good go by following the code posted the other day
> on c.l.py [1] (although I'm now not sure about the l10n
> aspects which Christian mentioned). Any technique of
> going up one (from your own profile) and then down one
> is no better than assuming that all users are in /home
> on a *nix box.

A while ago I've seen a variant of ExpandEnvironmentStrings that takes a
user token, too. It's called ExpandEnvironmentStringsForUser().
http://msdn2.microsoft.com/en-us/library/aa373507(VS.85).aspx

Before anybody gets exciting about the good news: Here is the bad news.
A user token can't be obtained easily. In fact it requires a login +
password or a process handler. :(

> As to a logged-on user's *own* home path, I'd prefer
> HOMEDRIVE/PATH over USERPROFILE since the latter is at
> least explictly named HOMEsomething, although the latter
> can be the fallback. Both are present on Win2k & on WinXP.
> Can't check WinNT or Win9x but I don't know if we're looking
> to support those or not.

Python 2.6 targets Windows 2000 and newer. So no, we don't have to
support NT and the 9x series any more.

Christian



More information about the Python-Dev mailing list