Link to home
Start Free TrialLog in
Avatar of ypm
ypm

asked on

WMI get Client Name(machine name) and Session type from Windows Task Manger

How can we get the remote client name & session from the task manager using WMI. We have many servers in our company and need to see who is logged on and the machine name. Using WMI we are able to get the User, ID, and Status from each server.  Everything we have so far works great. These last two items, Client Name and Session or rather Session Type are proving to be a real headache to retrieve. We use VB.Net and Visual Studio 2010 on Windows 7. We would prefer for it to be in managed code but are open to other options except scripting. A VB.Net or C# sample of any kind would be very helpful.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I am not sure that I understand what you mean by "Client Name"...

For session, do you mean Win32_LogonSession?

Win32_LogonSession class
http://msdn.microsoft.com/en-us/library/aa394189(v=vs.85).aspx
Avatar of ypm
ypm

ASKER

XP:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_whats_there_w.mspx?mfr=true

Win7:
http://www.techrepublic.com/blog/windows-and-office/reap-the-benefits-of-windows-7s-task-manager/2576/

1. Start "Windows Task Manager"
2. Go to the Users tab.
3. Look at the columns(go to menu - View, Select columns, if you don't see it.)
4. Look at the column called "Client Name"
5. Win32_LogonSession will not give the information needed. As said, we have most of the information already. Just need the last columns mentioned.

Already in use: Win32_TerminalService, win32_logonsession, Win32_Process, Win32_ComputerSystem, and Win32_UserAccount. None of these give us the last bit of information we would like to see.

If you have XP or better, you can see these columns under Windows Task Manager.
You may obtain a list of connected users by executing qwinsta:

http://weblogs.asp.net/owscott/archive/2003/12/30/Managing-Terminal-Services-Sessions-Remotely.aspx

Cassia .NET library is probably the tool you are looking for: http://code.google.com/p/cassia/
Avatar of ypm

ASKER

We know of qwinsta and it does not give the remote machine name of each logged on user.  We don't need the users list. As stated we already have that and more. We need the machine name of each logged on user.

Example:  1st user logged on as xyz with machine name of z123
                  2nd user logged on as pdq with machine name p123
                 and so on.

We need the machine names: z123, p123 for each logged on user.  We don't need the server name as that's obvious already.

Don't know how to be any more clearer than this.

We looked Cassia .NET library  and it does not provide the machine name.
Also we really don't want any third party libraries in this stand alone application. Right now it's all .net microsoft controls.
I fully understand what you need.

The question is Why to reinvent the wheel? Cassia is working solution which you can use.

If you don't like such solution then you may call the RDS API functions directly. They are simple and fully described here: http://msdn.microsoft.com/en-us/library/aa383833(v=vs.85).aspx

Usable source code is here: http://www.codeproject.com/Articles/111430/Grabbing-Information-of-a-Terminal-Services-Sessio

To obtain client PC name from known IP should not be difficult.
Avatar of ypm

ASKER

Ok, we are going to call this one a loss. The point is just not getting across.
The first url does not even come close to what we asked for.
If we had the ip address, it would be no problem to get the machine name without all the bloated code on code project .
We only have a user, id, and status.
Cassia does not seem to have the ability to enter a domain, a remote user, and a remote user password.
It works on a local machine.

A similar question was posted on this exchange and never really answered.
https://www.experts-exchange.com/questions/22550879/VB-NET-Terminal-Services-Machine-Name.html
Using SET at the command prompt on the remote machine is not a solution.

We appreciate the effort and will leave this up here for one more day and then ask for it to be closed. Thanks for all your effort.
I know my posts did not answer your questions exactly as you would wish... I've been pointing to places where you can obtain relevant info (OK, not in all cases :-).

The WTSQuerySessionInformation calls in the last link should be your starting point. It gives you the IP address, user, domain etc. (Of course, IP can be the router IP in some cases.) The MSDN link on the same post contains all the RDS API functions described.

Hope somebody else will tell more.
ASKER CERTIFIED SOLUTION
Avatar of ypm
ypm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ypm

ASKER

No solution presented.