Thanks for your help Peter; I have achieved what I wanted.
I initially tried what you suggested, finding the PDC and enumerating all the servers connected to it and enumerating all of the sessions connected to each server. This worked, but very slowly (we have about 150 servers and could have up to 7000 users on the domain. It took 15 – 25 minutes to run, depending on how busy things were. As I wanted this to be something a Help Desk Operator to use to establish the machine a customer was logged onto while they were recording the customers details this did not fulfil the requirement.
My aim was to provide useful information for computer support people, so my program also provided information on the home of their roaming profile (“User Profile Path:” in User Manger), the location of their data (the Connected “Home Directory” in User Manger) and their Full Name: (in User Manager). It occurred to me that all of our normal users would have a connection to a “Home Directory” on a server and that the name of that server was available to me. My approach was then to establish the “Home Directory” of the person I was interested in, break this down to give me the server element and then enumerate the sessions running on that server. The connections are made as the user logs on, and so you can reasonably be certain that if someone is logged on they will be connected to this server.
If the user is connected from more than one computer the dialogue box adds each computer name to a drop down box, if there is only one it becomes the selected one from the list. If you click on the [Copy to Clipboard] button, the details listed above and the computer names. I also included the time the program was run, as people can move around (but don’t tend to) to establish the reliably of the information. I have pasted a slightly modified version of the paste (to protect the innocent) to show what you get. The users “Home Directory” is always configured as the Z: drive.
User Name: USER1 - (Jones, Andrew,)
Z: Drive: \\SERVER1\USER1$
Profile Location: \\SERVER2\PROFILES\USER1
Computer Name: COMPUTER55 - (Active: 22-07-2003 - 13:18:22).
COMPUTER56
This tool enables the Help Desk Operators to add the name of the computer either with the problem, or with the customer logged onto that has the problem. It provides information as to whether someone is logged on (without having to ring or visit). The reason it puts the list of Computers into a drop down box, allowing the user to select a specific one is that it does a couple of other things specific to this domain.