<p>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.</p>

Try this:
```
```
import os;
print os.environ.get( "USERNAME" )
```
```
That should do the job.