Discussion:
[Q]: How can I get the logged in users username on Win32?
Mark Hammond
2001-03-14 22:52:01 UTC
Permalink
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
win32api.GetUserName()

For WSH examples, check out the win32com\test directory.

Mark.
Fredrik Lundh
2001-03-14 16:27:35 UTC
Permalink
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?
in case you really meant to post this again, here
In other words, how can I get the username in Windows?
getpass.getuser()
(it works as long as USERNAME is set, which it usually is)
And win32api.GetUserName() should work even if it isnt :)
Cheers /F
Rolander, Dan
2001-03-02 13:11:47 UTC
Permalink
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
Werner Schiendl
2001-03-14 14:18:08 UTC
Permalink
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>
I installed the ActivePython distribution from ActiveState and this works by
default.
Just give your file the extension ".pys" and it works.

Samples are found in the installation as well (Python 2.0)
<Install-Dir>\win32comext\axscript\demos\client\wsh

hth
werner
TIA
nomad
nomad
2001-03-16 14:32:27 UTC
Permalink
Thanks - I can stop pulling my hair out now...

On Wed, 14 Mar 2001 22:52:01 GMT, Mark Hammond <MarkH at ActiveState.com>
Post by Mark Hammond
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
win32api.GetUserName()
For WSH examples, check out the win32com\test directory.
Mark.
nomad
2001-03-02 07:56:06 UTC
Permalink
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
nomad
2001-03-14 14:06:54 UTC
Permalink
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

Loading...