1

Using WMI (regardless of the actual programming language), it's possible to get the currently logged on user using a query such as Select UserName from Win32_ComputerSystem. All nice and good.

But what if multiple user sessions and/or Terminal Services are involved? Is it possible to list all the currently logged on users on a given system? How?

If WMI is not the best option here, and/or if there are other available tools, feel free to advice. I'm mainly interested in .NET/C#.

Massimo
  • 1,520
  • 1
  • 19
  • 36

2 Answers2

0

What you want is WTSEnumerateSessions, however this will involve a p/invoke call. If you want a nice c# wrapper library I recommend cassia. As for a purely WMI solution I do not know.

Found a MSDN post about some WMI calls that are similar to what you want.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
0

This answer already exists on net. Did you try Google? I did and found (all WMI related) -

  1. StackOverflow question (this makes your question a duplicate)

  2. MSDN blog entry - worth trying

  3. Web search result

I strongly recommend using a search engine first - stackoverflow/web - and if you still can't find answers, go ahead and post your question!

Community
  • 1
  • 1
Nayan
  • 3,092
  • 25
  • 34
  • 3
    That's exactly what I did. I searched a lot, and this is how I found the WMI query I quoted in the question; I also had already stumbled upon some of your links, like the third one (which uses exactly the same query, and so only shows one user). Others seem more promising, mainly the SO one. Thanks for your answer, but please try to not be so rude. – Massimo Oct 11 '10 at 19:55
  • Massimo, I wasn't being rude, but I'm aware that my direct answer might appear so. :) I was trying to show how to usually go about finding a solution. – Nayan Oct 12 '10 at 02:33