How to get user home directory on Windows
thebjorn
BjornSteinarFjeldPettersen at gmail.com
Sun Jan 13 10:01:49 EST 2008
On Jan 12, 6:50 pm, "Giampaolo Rodola'" <gne... at gmail.com> wrote:
> 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'
Check out http://msdn2.microsoft.com/en-us/library/bb762181(VS.85).aspx
for some of the complexities of special directories on Windows.
If you give more details on what you need to get done, someone might
come up with a better solution (my instinct tells me this might be a
database problem, but then I'm a database person so that might not be
terribly relevant ;-)
-- bjorn
More information about the Python-list
mailing list