How to get user home directory on Windows

Tim Golden mail at
Mon Jan 14 04:02:38 CET 2008

Martin P. Hellwig wrote:
> Giampaolo Rodola' wrote:
>> Hi all,
>> I'm trying to use the pywin32 extension to find out the user's home
>> directory but currently I didn't find a solution yet.
>> What I'd need to do is not getting the home directory of the currently
>> logged in user but something like:
>>>>> get_homedir("frank")
>> "C:\home\users\frank"
>>>>> get_homedir("josh")
>> "C:\home\users\josh"
>> Is there a way to do that?
>> I tried to search through the Pywin32 documentation with no luck.
>> In addition I'm not practiced with the Windows API at all.
> Well, windows, to my knowledge, uses the same base path for all profiles 
> (this is not true for the My Documents folder which can differ). So what 
> you could do is get the location from the ALLUSERPROFILE environment 
> variable, go one folder higher and iterate through that.
> Ignoring the folders for the 'pseudo' users: 'All Users', 'Default 
> User', 'LocalService' and 'NetworkService'.

The trouble with that is that any particular user's profile can be
specifically overridden. I'm not attached to an AD network here,
but I think a networked user's profile can be network based
(whike a local user's won't be, say). And there are other ways
to change the profile too, down to hacking the registry as
described here:

That said, it'll probably work for a lot of the people for
a lot of the time.


More information about the Python-list mailing list