Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the Name of a Remote Computer from the User Name 1

Status
Not open for further replies.

MMikeO

Programmer
Apr 4, 2003
3
GB
I would like to write a program which will give me the name of the computer that is currently being used by a particular User Name. The User will have the "User Name", which would be entered into a dialogue box, the utility would then go off and find the "Computer Name" for that user and display it and some other useful information to the utility user. The other useful information will include things like location of profile and home share (I think I can get this information without any help).

The aim of the tool is to enable Help Desk and support people to identify the computer someone is currently using to enable them to connect up to it remotely.

I have look for utilities that would do this and can't find anything, though the MS Net presumably does this as you send a message to a user name and it is displayed on the computer that person is using?
 
"... though the MS Net presumably does this as you send a message to a user name and it is displayed on the computer that person is using" --> I guess it is just doing a broadcast to the entire network which is only displayed by systems having the user logged in. Marcel
 
There's an important difference between those two approaches. If you send a message to an entire network to be displayed only on computers where a particular user is logged on, it should work no matter how many computers they've logged on to. If you want to get an answer back as to which computer they're logged on to, it's going to get more complicated if they're logged on to several..
 
Yes I agree they may be and Net Send only sends the message to one machine if they are. What my intended program does in response to this would depend on the technicalities of obtaining the information. But if it were easy to get the 'Computer Names' of all the machines a particular user was using I would do so. On the network I intend to use this the majority of people would only be likely to use one at a time.
 
I know how.
In a NT4.0-domain, do the following:

1. Use NetGetDCName(..,domainname,...) to find the PDC.
2. Use NetServerEnum() to find all the servers in your domain. (Not workstations).
3. For each server use NetSessionEnum(server,NULL,username,10,&buffer,...) If it returns NERR_Success, buffer.sesi10_cname contains the name of the workstation the user is logged in to.

If you have many servers, then you may get many equal servers. If the user is logged inn, but not attached to any servers, you won't find him.

 
Spelling error. I meant:

If you have many servers, then you may get many equal answers. If the user is logged in, but not attached to any servers, you won't find him.

And I forgot to say, that each NetSessionEnum returns an array of results, so you must go through each result. (If the user is logged in to more than one computer).
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top