perlclient-serverwindows-users

Perl code to retrieve currently logged user list of windows server


Clients are connecting to a windows server with different user names. For example:

Now there are 3 currently logged users at server: user1, user2, user3.

Is it possible retrieve logged on users and client name? I can see this at task manager at user form as seen at below picture:

user and client list at task manager


Solution

  • I don't use Windows, but I can Google enough to guess at a solution.

    This page suggests that you can use query user to get a list of logged in users.

    You can run that command in Perl and capture the output using qx[].

    # All output in a scalar
    my $users = qx[query users];
    
    # One line of output per element in an array
    my @users = qx[query users];
    

    You know have the information that you want in a Perl variable. The next step is to parse that data to extract the specific fields that you need. As I don't currently have access to a machine running Windows, I can't see what format this command returns, so I can't help you with this second part of the process.

    If you have trouble parsing the data, then post a sample of it in a new question here and we'll be happy to help you further.