Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: get currently logged user and his/her special folders

Does this code win32api.GetUserName() works fine on all win system from win 2000 to win 7 ? What about if user is not local user but domain user, does it still work ?

When i use this function shell.SHGetFolderPath(0, shellcon.CSIDL_someDirectory, 0, 0), do I get wanted folder for currently logged user ?

Any help appreciated.

like image 419
Primoz Avatar asked Jan 19 '26 08:01

Primoz


1 Answers

There is a module called getpass which has a getpass.getuser() function. This should work on all windows versions. It did on all the versions I've tried anyway. The user I've used wasn't local either.

like image 173
Mattias Nilsson Avatar answered Jan 22 '26 01:01

Mattias Nilsson