How can I retrieve the name of the currently logged in user, using a python script? The function should work regardless of whether it is a domain/ad user or a local user.
views:
1580answers:
3
+5
A:
Try this:
import os;
print os.environ.get( "USERNAME" )
That should do the job.
Steve Kemp
2008-09-22 19:42:41
Is it get() or getenv()?
Marcel Levy
2008-09-22 19:45:31
http://www.a-a-p.org/exec/tutor-python.html seems to support my usage.
Steve Kemp
2008-09-22 19:48:42
A:
I don't know Python, but for windows the underlying api is GetUserNameEx, I assume you can call that in Python if os.environ.get( "USERNAME" ) doesn't tell you everything you need to know.
Jim In Texas
2008-09-22 19:48:00
+1
A:
win32api.GetUserName()
win32api.GetUserNameEx(...)
See: http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html
Adam
2010-01-02 21:31:16