[python-win32] Finding users home directories
Giampaolo Rodola'
billiejoex at gmail.com
Sat Jan 12 22:37:06 CET 2008
2008/1/12, Giampaolo Rodola' <billiejoex at gmail.com>:
> 2008/1/12, Guilherme Polo <ggpolo at gmail.com>:
> > 2008/1/12, Giampaolo Rodola' <billiejoex at gmail.com>:
> > > Hi,
> > > I'm trying to use the pywin32 extension to find out the users home directories.
> > > Currently I found a way for doing that but it requires to validate the
> > > user by providing its 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, in
> > > the same way as if I would on UNIX where it would be enough just using
> > > the pwd module and providing the username only:
> > >
> > > >>> import pwd
> > > >>> pwd.getpwnam('user').pw_dir
> > > '/home/user'
> > >
> > > Does someone know if it is possible to do that?
> >
> > Did you try:
> >
> > import os
> > os.path.expanduser('~user')
>
It doesn't seem to be what I'm searching for:
>>> os.path.expanduser('~')
'C:\\Documents and Settings\\billiejoex'
>>> os.path.expanduser('~user')
'~user'
>>>
More information about the python-win32
mailing list