Many times, I need to find out the computers users are currently logged on to. Thus, I wrote FindLogon.vbs, which locates the machine a user is logged on to by looking at the open sessions on the user's home server and determining which computers those sessions-originate from.
Listing 1 shows an excerpt from FindLogon.vbs. You can download the entire script from the Windows Scripting Solutions Web site. Go to http://www.windowsitpro.com/windowsscripting, enter 48796 in the InstantDoc ID text box, then click the 48796.zip hotlink. I wrote this script for machines running Windows XP. To launch the script, use the command
CScript FindLogon.vbs domain\nt_id
where domain is the name of the user's domain and nt_id is the user's logon name.
FindLogon.vbs assumes that the home directory field in the user's domain account properties isn't empty. This field contains the name of the user's home server, which is needed to access that server's sessions. When a user accesses resources on a server, an active session is established-between the user's computer and that server. Sessions are managed by the file service. Thus, to obtain session objects, FindLogon.vbs binds to the LanmanServer service, as Listing 1 shows. The script then iterates through each session object to obtain the name of the computer involved in that session.