KingMak KingMak - 1 year ago 134
Python Question

How to make Python get the username in windows and then implement it in a script

I know that using

command, I can get the username, but how can I implement it in the following script automatically? So i want python to find the username and then implement it in the following script itself.

os.path.join('..','Documents and Settings','USERNAME','Desktop'))

(Python Version 2.7 being used)

Answer Source

os.getlogin() return the user that is executing the, so it can be:

path = os.path.join('..','Documents and Settings',os.getlogin(),'Desktop')

or, using getpass.getuser()

path = os.path.join('..','Documents and Settings',getpass.getuser(),'Desktop')

If I understand what you asked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download