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

Immaculate monks

I need to obtain number of basic information regarding few remote winXP PC’s that I have here in my AD. One of bits of information that I need is “who is actually logged on to a particular PC”. And for this I have the following script which doesn’t seem to work! i.e No output or error msg!
#! c:/perl/bin/perl.exe -slw use strict; use Win32; use Win32::NetAdmin qw(LoggedOnUsers); use Win32::AdminMisc; use CGI qw (:standard); my $data = param('hostname') || Win32::NodeName(); my $user = Win32::AdminMisc::GetLogonName(); print "\n\nHello $user,...\n"; print "Remote Hostname is => $data\n"; my $IP = Win32::AdminMisc::GetHostAddress($data); print "Remote TCP/IP Address is => $IP\n"; ### THIS BIT BELOW DOESN’T SEEM TO WORK!### if (! LoggedOnUsers( "$data", my %user_ref)) { print "\n\n Not happening\n\n"; } else { print "\n\nwahey\n\n"; }
Any help please

Blackadder

Replies are listed 'Best First'.
Re: Finding out who has logged on remotely!
by InfiniteLoop (Hermit) on Mar 29, 2005 at 12:43 UTC
    I have'nt used Win32::NetAdmin, but the document says this:

    LoggedOnUsers(server, userRef)
       Gets an array or hash with the users logged on at the specified computer. If userRef is a hash reference, the value is a semikolon separated string of username, logon domain and logon server.

    so I presume, you should be doing this:
    my %user_ref; LoggedOnUsers( "$data", %user_ref); if (!%user_ref){ print "\n\n Not happening\n\n"; }else{ print "\n\nwahey\n\n"; }
Re: Finding out who has logged on remotely!
by PodMaster (Abbot) on Mar 29, 2005 at 14:04 UTC
    which doesn’t seem to work! i.e No output or error msg!
    So it just hangs or what? You need to find out where it's failing (print print print print).

    Permissions may play a role ...

    UPDATE: is LoggedOnUsers failing or is it hanging? You're not doing proper error checking (When a function fails call Win32::NetAdmin::GetError() rather than GetLastError() or $^E to retrieve the error code.)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      These are the changes that I did, and it seems to work (I do get and display and no errors)!
      #! c:/perl/bin/perl.exe -slw use strict; use vars qw/%data/; use Win32; use Win32::NetAdmin qw(LoggedOnUsers); use Win32::AdminMisc; use CGI qw (:standard); my $data{host} = param('hostname') || Win32::NodeName(); my $data{user} = Win32::AdminMisc::GetLogonName(); my $data{IP} = Win32::AdminMisc::GetHostAddress($data{host}); print "\n\nHello $data{user},...\n"; print "Remote Hostname is => $data{host}\n"; print "Remote TCP/IP Address is => $data{IP}\n"; my %user_ref; LoggedOnUsers($data, \ %user_ref); if (!%user_ref) { print "\nOooops : "; print Win32::NetAdmin::GetError()."\n"; } else { while (my ($a, $b) = each %user_ref) { print "$a, $b\n"; } }
      The Output
      Hello SYSTEM,... Remote Hostname is => DNA001910 Remote TCP/IP Address is => 10.60.1.54 6, amy.miles;UK;GENRUNUDC02 3, Administrator;UK;GENRUNUDC02 7, Administrator;UK;GENRUNUDC02 9, Administrator;UK;GENRUNUDC02 2, Administrator;UK;GENRUNUDC02 8, claire.calway;UK;GENRUNUDC02 1, Administrator;UK;GENRUNUDC02 4, Administrator;UK;GENRUNUDC02 0, DNA001910$;CASH; 5, Administrator;UK;GENRUNUDC02
      But I still have few questions?

      1- is no 9 is the last person to login?

      2-when I change the parameter in the URI the display doesn't change! i.e if I enter a URL http://localhost/cgi-bin/test.cgi?hostname=dna1111119 then I would get a display of some sort but if I change the hostname to something else, the display doesn't change!!!

      3-do I need the line print "Content-Type: Text/Plain\n\n" in every CGI code! it seems if I omit this line my MS-IE browser throughs error 500!

      Please enlighten me,.....Thanks indeed

      Blackadder