0

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

  • client1 connects to server with user1
  • client2 connects to server with user2
  • client3 connects to server with user3

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

kadir_beyazli
  • 197
  • 2
  • 12
  • i think the question is not specific to perl but to operating system maybe [How to display currently connected users/workstations to a Windows SMB Share?](https://superuser.com/questions/783950/how-to-display-currently-connected-users-workstations-to-a-windows-smb-share) or [How do I access the list of currently logged on users through Terminal Services Manager in Windows Server 2012?](https://serverfault.com/questions/471224/how-do-i-access-the-list-of-currently-logged-on-users-through-terminal-services) could help – Nahuel Fouilleul Jan 19 '18 at 09:04
  • @NahuelFouilleu the links you offered shows the ways of displaying users from task manager or cmd. I know those ways but l need to insert currently logged users to database and reporting so seeing from task manager or cmd is not enough for me. – kadir_beyazli Jan 19 '18 at 12:31
  • this information is provided by the operating system, perl can call system command for example `perl -e 'print for qx(c:/windows/system32/cmd.exe /c "echo hello")'` (sorry backquotes don't work with SO – Nahuel Fouilleul Jan 19 '18 at 12:48
  • @NahuelFouilleul this information must be stored somewhere. For example it may be stored in a file so I can read that file. Or it may be supplied with programming language command returning an array list. For example currently logged user can be retireved with programming code. this means all users can be too – kadir_beyazli Jan 19 '18 at 15:45

1 Answers1

2

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.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97