Solved

Show users logged into (w2k) domain/server

Posted on 2006-10-25
16
414 Views
Last Modified: 2012-06-27
Hi,

Does anyone know how to enumerate a list of the users logged into either the domain, or a specific domain controller (either is fine)?  
For the application I'm developing I'd need to be able to do this for normal (none-administrator) users using XP Pro workstations (Framework v2) within the same domain.

I've looked on MSDN and googled aroudn and only seem to find ways of showing users on local machines.  Anyone been here before and had success?
Thanks,

- Moz
0
Comment
Question by:nikez2k4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
16 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17802207
OK. This will only be partially helpful.

There is a sysinternals utility called PsLoggedOn which will tell you who is logged on to a specific machine/server.
It comes with source code so you could get a look at how it's done and see if you can either reuse it or replicate its behaviour.

http://www.sysinternals.com/Utilities/PsLoggedOn.html

Basically it uses the NetEnumSession API.
0
 
LVL 1

Author Comment

by:nikez2k4
ID: 17802379
Thanks for the link - Yeah, that's in C as well (you think my c# is bad, you should see my C!) :-)
I had a google around for NetEnumSession API, could only find a few 404s and nothing much of any help.  Thanks for taking the time tho.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17802503
You can also do this using WMI in C#.

Basically you can query all the sessions on a local machine like this :

using System;
using System.Management;

class WMITest{

    public static int Main(string[] args) {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_SessionConnection");
        foreach (ManagementObject session in searcher.Get()) {
      foreach (PropertyData p in session.Properties){
            Console.WriteLine(p.Name + " = " + p.Value);
            Console.ReadLine();
      }
        }
        return 0;
    }
}

You can also connect to the WMI interface on a remote machine and do the same thing.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:nikez2k4
ID: 17802667
Thanks for the reply, yeah - I'd been looking at WMI stuff on the MSDN but couldnt see how to make it search all the workstations out there (or simply query the FR DC) - I've tried your code example - compiles fine but only returns the username of the PC I'm on now (me!), rather than everyone.  Is this what you meant?
Thanks again.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17803572
The example shows querying the local WMI provider.
You can coonect to another machine and run a similar query against that to find out who is logged on to to it both locally and remotely.
0
 
LVL 1

Author Comment

by:nikez2k4
ID: 17803746
That'd be okay for a few machines but I'd (ideally) want to get all the users logged in and there are over 700 PCs/Laptops on the network so it'd be too many to add in for looking "manually" .
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17803905
It should not be too hard.

You can :

    get a lits of all machine accounts from the domain
    go thourgh each one and poll the machine to see if it's active/switched on
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17803991
ooops...

    if its active
       remotely query its WMI to see who's logged on
    if not
       skip

That should do it.

In your question you said you wnated to see users logged on to a domain or specific domain controller in which case you wouldn't have to query each PC just the servers in question.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17805073
What operating system is your domain controller running?
0
 
LVL 1

Author Comment

by:nikez2k4
ID: 17809897
Windows 2000 (Will be upgraded to 2003 in around 5 months)
All workstations are using XP Pro.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17813313
The WMI suggestion is ideal, because it would only have to be run against the server in question (not on all the workstations).  To query WMI on a remote machine, you can modify ozymandias' code:

//If authentication is required.

  System.Management.ConnectionOptions connection = new System.Management.ConnectionOptions();
  connection.Username = "administrator";
  connection.Password = "password";

  System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\SERVER_IP_ADDRESS\root\cimv2", connection);

  ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(scope, "SELECT * FROM Win32_SessionConnection");

//If authentication is not required:

  System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(@"\\SERVER_IP_ADDRESS\root\cimv2", "SELECT * FROM Win32_SessionConnection");

The catch is, it requires Windows Server 2003.
0
 
LVL 1

Author Comment

by:nikez2k4
ID: 17829283
Okay, I'll hang-fire until the upgrade, Thanks for your help!
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17997463
nikez2k4, I would like to suggest you accept ozymandias's first comment as the solution as it was the only one offered that works on your current operating system.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question