Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Finding username in Win32

by esr (Scribe)
on Oct 12, 2006 at 20:48 UTC ( #577959=perlquestion: print w/ replies, xml ) Need Help??
esr has asked for the wisdom of the Perl Monks concerning the following question:

In Windows XP where there are multiple user accounts defined, is there a Perl function to determine the user/account name of the current user. None of the usual Unix "getpw*" functions work in Windows.

Comment on Finding username in Win32
Re: Finding username in Win32
by Corion (Pope) on Oct 12, 2006 at 20:51 UTC

    $ENV{USERNAME} will likely hold the name of the user currently logged on on Win32.

Re: Finding username in Win32
by blazar (Canon) on Oct 12, 2006 at 20:59 UTC
    In Windows XP where there are multiple user accounts defined, is there a Perl function to determine the user/account name of the current user.

    Not exactly a function but $ENV{USERNAME} should be pretty portable:

    C:\temp>perl -le "print $ENV{USERNAME}" Blazar
Re: Finding username in Win32
by planetscape (Canon) on Oct 12, 2006 at 21:22 UTC
Re: Finding username in Win32
by swampyankee (Parson) on Oct 12, 2006 at 22:43 UTC

    If you've got ActiveState's version, scan through your documentation for the Win32 module, looking for LoginName. According to the docs,

    Win32::LoginName() [CORE] Returns the username of the owner of the current perl process.

    emc

    At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

    —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://577959]
Approved by Hue-Bond
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-08-02 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls