How to get user home directory on Windows

Giampaolo Rodola' gnewsg at gmail.com
Sat Jan 12 18:50:16 CET 2008


Update.
I found a way for getting the home directory of the user but it
requires to validate the user by providing username+password:

def get_homedir(username, password):
    token = win32security.LogonUser(
        username,
        None,
        password,
        win32security.LOGON32_LOGON_NETWORK,
        win32security.LOGON32_PROVIDER_DEFAULT
        )
    return win32profile.GetUserProfileDirectory(token)

What I'd like to do is avoiding the requirement of the password, the
same way as if I would on UNIX where it would be enough just using the
pwd module:

 >>> import pwd
 >>> pwd.getpwnam('user').pw_dir
 '/home/user'




More information about the Python-list mailing list