arunmep has asked for the wisdom of the Perl Monks concerning the following question:

hi guys, I want to get the user login name in win2000 & 98 is it possible through perl if any modules availbale to do this please let me know
  • Comment on How to get the User login name in Win2000

Replies are listed 'Best First'.
Re: How to get the User login name in Win2000
by BrowserUk (Patriarch) on Sep 08, 2006 at 05:41 UTC

    $ENV{USERNAME}

    may be all you need.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to get the User login name in Win2000
by jdtoronto (Prior) on Sep 08, 2006 at 05:37 UTC
Re: How to get the User login name in Win2000
by greatshots (Pilgrim) on Sep 08, 2006 at 06:39 UTC
Re: How to get the User login name in Win2000
by jfluhmann (Scribe) on Sep 08, 2006 at 13:46 UTC

    Something I used to use when I was working on a desktop management system was similar to the following:

    #!/usr/bin/perl use strict; use warnings; use Win32::OLE 'in'; $Win32::OLE::Warn = 3; my $server = shift; my @users = (); getLocalUsers($server,\@users); print "Local User Accounts for $server:\n"; foreach( @users ) { print $_ . "\n"; } # USE: getLocalUsers(<computer>,\@<list>) sub getLocalUsers { my $strComputer = shift; my $users = shift; my $colAccounts = Win32::OLE->GetObject("WinNT://" . $strComputer); $colAccounts->{'Filter'} = ["user"]; map { push @{$users}, $_->{'Name'}; } in $colAccounts; }

    The @users seemed to also include user accounts that current processes were running under. You could probably just filter them out.

    Jeremy