How can I get the logged in users username on Win32?

Rolander, Dan Dan.Rolander at marriott.com
Fri Mar 2 08:11:47 EST 2001


It's pretty easy to use Python with WSH. Install the win32all extensions,
which will register the ActiveX scripting engine. Then just create a python
script with a .pys extension. Here's an example that will display the
machine name and currently logged on user:

  # wsh.pys
  # A Windows Scripting Host file that uses Python
  objNet = WScript.CreateObject("WScript.Network")
  WScript.Echo(objNet.ComputerName + " - " + objNet.UserName)

To run it use the command: wscript "W:\My Documents\Source
Code\WSH\PythonScripts\wshdemo.pys"

There is a chapter on Active Scripting in the book Python Programming on
Win32 by Mark Hammond & Andy Robinson. I highly recommend you get it.

HTH,
Dan

-----Original Message-----
From: nomad***@***freemail.absa.co.za
[mailto:nomad***@***freemail.absa.co.za]
Sent: Friday, March 02, 2001 2:56 AM
To: python-list at python.org
Subject: [Q]: How can I get the logged in users username on Win32?


Howzit,

After searching through the Python Docs, I found that on Un*x I could
use getpass.getuser(), but there is no equivalent for the Win32
platform.

In other words, how can I get the username in Windows?

As a side note, how can I enable Windows Scripting Host support for
python - there is mention of python in the original WSH docs - and if
I can use python scripts in WSH how would I call the built-in
Wscript.<methods>

TIA

nomad
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list