How to Get the Name of the Workstation a User is Currently Logged Into
Keywords:
Question:
Is there a way to get the name of the workstation a user is currently logged into?
My requirements aren't actually that complex. I'm building an app that is going to present me with a list of
people using a certain client server app. I have various tools that give me information:
- A tool that tells me who's logged in to the application. This will give the user login for the app (different to
the network login id), and the computer name of their workstation.
- Another app (Pervasive monitor) that gives me the windows login ID and an IP address.
- Various other bits and pieces of information.
Really, all I want to do is match the win login to a computer name so I can expose the app login ID
underneath it. To do this, I need a function (an API call perhaps) that gives me the name of the worstation a
particular use is currently logged on.
I can't find one though.
Answer:
There's a free Netbios-Utility call NTNAME.EXE on the net, which returns the name of the machine where
a user is (already) registered. Is old 16-bit but works
still in XP.
From what context are you trying to make this determination?
For example, are we talking about the situation where the user is logged in on a workstation and the script is
being run by that user on that same workstation?
- Or, is this a situation where a user is logged in on a workstation, has a drive letter connected to a server, and
the script is being run on the server and it trying to figure out which workstations are being used by all the
users who have active sessions on the server?
- Or, is it yet another scenario where the script is being run in a terminal server session by a user who is
logged on to a Windows Terminal Server system [including Citrix] and the script is trying to figure out the
name of the client PC from which the terminal server client is being run?
- You can always find out the name of the local workstation on which you are logged on by reading the
registry:
ComputerName = RegQueryValue(@REGMACHINE,"System\CurrentControlSet\Control\ComputerName\ComputerName[ComputerName]")
This works for me and I use it a lot.
If you are in the second scenario I don't know for sure if it is possible.
In the third scenario there are some terminal server related functions that can get the terminal server client
workstation's name, but these can be fooled by environment and .INI file settings when Citrix is being used.
Resolution:
I can use ipAddr2Host to resolve an IP to a computer name, and backtrack to the user through that.
Article ID: W15165
File Created: 2002:09:05:13:50:12
Last Updated: 2002:09:05:13:50:12