This will list users having a network session to a server. 
Syntax is 

Perl  scriptname.pl   computername
or 
Perl  scriptname.pl   \\computername



# NetSessionEnum($server, $client, $user, \@info)
# Provides information about all current sessions on server \\$computer.
# Specify target computer as argument to the script 
# (with or without preceding '\\')
use Win32::Lanman ;

$computer = "$ARGV[0]" ;
$sessions_number = 0;

$computer = substr($computer,2,) if (substr($computer,0,2) eq "\\\\") ;
print "------------[Logged in users on $computer]------------\n" ;

if(!Win32::Lanman::NetSessionEnum("\\\\$computer","", "", \@sessions)) { 
        print "Sorry, something went wrong; error: "; 
        # get the error code 
        print Win32::Lanman::GetLastError();
        print " : $^E\n" ;
        exit 1; 
        }

print "\n" ;

foreach $session (@sessions) { 
    @keys = keys %$session;
    if (${$session}{username} ne "") {
    print ++$sessions_number . "\t" ;
                
    foreach $key (@keys)  {
     if ($key eq "idle_time" or $key eq "time") {
      $hours=(${$session}{$key}) / 3600 ;
      print "$key=$hours" . "." x (30 - length($hours) ) ;
      }
     else {
      print "$key=${$session}{$key}" . "." x (30 - length(${$session}{$key})
) ;
      }
    }
print "\n" ;

  }
        
}

print "\n" ;


_____________________________________________
Bruno Bellenger
Sr. Network/Systems Administrator 
        
        -----Original Message-----
        From:   [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
        Sent:   mercredi 14 mars 2001 12:02
        To:     [EMAIL PROTECTED]
        Subject:        Finding Logged in users

        Hi,

        I have today seen reference to and have installed the lanman module.

        I cant find any documentation for it.

        I would like to use it to find the logged in users to our
development
        server at http://xxx.xxx.xxx

        I am using NT and are connected to it via our own intranet.

        I have tried the following code but it gives an error 123

        # NetWkstaUserEnum($server, \@info)
        # Lists information about all users currently logged on \\$computer.
        # Specify target machine as argument (with or without preceding \\)

        #==============================================
        # SPECIFY TARGET COMPUTER AS FIRST ARGUMENT;
        #==============================================
        use Win32::Lanman ;

        #$computer = "$ARGV[0]" ;
        $computer = '//rwaldock' ;

        print "\n" ;

        $computer = substr($computer,2,) if (substr($computer,0,2) eq
"\\\\") ;
        print "------------[Listing logged in users on
$computer]------------\n" ;

        if(!Win32::Lanman::NetWkstaUserEnum("\\\\$computer", \@info)) {
             print "Sorry, something went wrong; error: ";
             # get the error code
             print Win32::Lanman::GetLastError();
             print " : $^E\n" ;
             exit 1;
             }

        foreach $user (@info) { @keys = keys %$user;
                foreach $key (@keys)
                {
                       ${$user}{$key} =~ s/^a-//i ;
                            print "$key=[${$user}{$key}]\t";
                            $mail_alias = ${$user}{username} ;
                }

        print "\n\n" ;
        }

        I am very new to this module and have almost no idea what it does or
how it does it and would appreciate any help.

        I have full access to the web server via pc-anywhere and so I can do
anything to it.

        I am using to try to find out what students are logged in to it and
using Frontpage.

        Thanks
          Roy

        _______________________________________________
        Perl-Win32-Admin mailing list
        [EMAIL PROTECTED]
        http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to