Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

users for NT/2K

by idnopheq (Chaplain)
on Apr 23, 2001 at 14:54 UTC ( #74679=sourcecode: print w/ replies, xml ) Need Help??

Category: NT Admin
Author/Contact Info idnopheq
Description: users - display a compact list of users logged in

users lists the login names of the users currently on the system in a compact, one-line format.

#!/usr/local/bin/perl -w

use strict;
use Win32::NetAdmin;
use vars qw ( @WhoList );

my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/;

my $warnings = 0;

# Print a usuage message on a unknown option.

$SIG {__WARN__} = sub {
    if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"};
    require File::Basename;
    $0 = File::Basename::basename ($0);
    $warnings = 1;
    warn "$0: @_";

$SIG {__DIE__} = sub {
    require File::Basename;
    $0 = File::Basename::basename ($0);
    if (substr ($_ [0], 0,  5) eq "Usage") {
        die <<EOF;
$0 (NT Perl bin utils) $VERSION
$0 [ -h ]
    die "$0: @_";

die "Usage" if $ARGV[0];

my $Server = "";

Win32::NetAdmin::LoggedOnUsers (
  or die "$^E\n";

foreach my $UserName ( @WhoList ) {
    print "$UserName\t";


=head1 NAME

B<users> - display a compact list of users logged in


B<users> [ -h ]


B<users> lists the login names of the users currently on the system in
+ a compact, one-line format.

=head2 OPTIONS

The following options are supported:

=over 4

=item -h

Display syntax.


=head1 EXAMPLE

Below is an example of the B<users> output:

C:\> users
shoehorn        Administrator


The working of B<users> is not influenced by any environment variables

=head1 BUGS

B<users> isn't as nice as I would like, but Win32 isn't Unix, now is i

I did not bother to work on the formatting of the output beyond a tab 
+between users.


It does not make sense to talk about standards in a B<users> manual pa


    Revision 1.0  2000/06/22 10:32:57  idnopheq
    Initial revision

=head1 AUTHOR

The Perl implementation of B<users> was written by Dexter Coffin, I<id>.


This program is copyright by Dexter Coffin 2000.

This program is free and open software. You may use, copy, modify, dis
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.

=head1 SEE ALSO

=for html
<a href="who.html">who</a><p>



Comment on users for NT/2K
Download Code
Replies are listed 'Best First'.
Re: users for NT/2K
by AVisgoth (Initiate) on Jan 19, 2005 at 18:54 UTC
    Just as a question: The code you provide works perfectly, however is there any way to return only a single user from the list being returned? I have an issue that I keep getting service accounts listed, while I am concerned only with the last one, which is normally a user account. Any help would be appreciated.

Back to Code Catacombs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://74679]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-10-08 18:49 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (223 votes), past polls