How to get a computer name from a user name in VBscript/ASP
Posted on 2004-08-13
I work on the helpdesk for a large organization, and am looking for a way to get a host name from a username using VBscript in an ASP page. I'd like for other helpdesk staff to submit a username on the page, and have it return the name(s) of the computer(s) their currently logged into. Sorry, I'd offer more points on this one, but this is my first question on EE, and 125 is all i've got, but you can have 'em all.
I currently have 2 methods to pull computer name from user id's :
METHOD 1 :
[Use DOS to net send the user, and pull the info from the NBT cache]
> NET SEND jsmith2
> NBTSTAT -c
METHOD 2 :
[use vbscript to pull home directory of user, open computer manager & connect to home directory computer & look in the sessions folder for users name & info]
[error checking & other non-essential code stripped]
Set oFs = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments
UserName = oArgs(0)
Set myUser= GetObject("WinNT://WORKDOMAIN/" & UserName & ",user")
Set userClass = GetObject(myUser.Schema)
HomeDir = myUser.HomeDirectory
pos1 = InStrRev(myUser.HomeDirectory, "\")
HomeDir = Mid(myUser.HomeDirectory,3,pos1-3)
RunShellCmd("fsmgmt.msc -s /computer:\\"& HomeDir)
The problem with method 1, is that it isn't always current/reliable, and alerts the user on their PC when you net send them.
The problem with method 2, is that it isn't automated.
There's got to be a way to enumerate/export the info in the sessions folder on a logon server (computer mgr), search for the username in the list, and pull the ip/hostname(s).
Thanks for any help u can offer.