Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


<fredrik at effbot

Mar 2, 2001, 1:04 AM

Post #1 of 5 (933 views)
Permalink
How can I get the logged in users username on Win32?

"nomad" wrote:
> 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?

getpass.getuser()

(it works as long as USERNAME is set, which it usually is)

Cheers /F


Dan.Rolander at marriott

Mar 2, 2001, 6:11 AM

Post #2 of 5 (912 views)
Permalink
How can I get the logged in users username on Win32? [In reply to]

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
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


MarkH at ActiveState

Mar 2, 2001, 3:24 PM

Post #3 of 5 (918 views)
Permalink
How can I get the logged in users username on Win32? [In reply to]

Fredrik Lundh wrote:

> "nomad" wrote:
>
>> 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?
>
>
> getpass.getuser()
>
> (it works as long as USERNAME is set, which it usually is)

And win32api.GetUserName() should work even if it isnt :)

Mark.


ws-news at gmx

Mar 14, 2001, 7:18 AM

Post #4 of 5 (913 views)
Permalink
How can I get the logged in users username on Win32? [In reply to]

> 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


<fredrik at effbot

Mar 14, 2001, 9:27 AM

Post #5 of 5 (912 views)
Permalink
How can I get the logged in users username on Win32? [In reply to]

"nomad" wrote:
> 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
are the responses you got two weeks ago:

fredrik:
> > 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)

mark:
> And win32api.GetUserName() should work even if it isnt :)

Cheers /F

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.