Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 764
  • Last Modified:

How to get a computer name from a user name in VBscript/ASP

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)
WScript.quit()



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.

0
Gitcho
Asked:
Gitcho
  • 3
  • 2
  • 2
1 Solution
 
Gary DewrellSenior Network AdministratorCommented:
Hi Gitcho,

I can tell you a very low tech way to do it that I know works. If you are on a domain, add a line to the login script that writes the %computername% to a file in the users directory. Overwrite that file each time. Read that file from the known users directory.



God Bless
0
 
GitchoAuthor Commented:
Thanks dgewrell.  Not a bad idea - hadn't thought of that one, but not sure that I could make that work.

That write-once approach wouldn't tell you if a user was still logged on to any of the hosts - unless there was a way to write back at logoff.
If the PC bluescreened, you'd also be out of luck.

It might help a bit, but really need a VBscript solution that works for the Helpdesk intranet page.
0
 
Gary DewrellSenior Network AdministratorCommented:
Keep in mind I am not a programmer so this may no make sence but it seams logical to me.

What about a comobination of the two. To remove the file just add that to the logoff script that can be specified via GPO.
That will solve the issue of them logging off.

Then you have a vbscript that looks in the user directory for the specified file and read it. If the file does not exist you know the user is no longer logged on. If the file exist you read it to get the name of the PC that the user last logged onto. The write the code into you VB script to determine if that user is still logged on.  If he is do what ever it is that you wanted to do. If not have the vbscript delete the file from the users directory.  I have no programmed since the vb3 days but Im sure this can all be done in vbscript. If nobody with more experiance gives you a good answer, let me know and Im sure I can write this in vbscript. AFter all you know what they say, once you've learned to ride a bike, you never forget. :)

God Bless
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
David LeeCommented:
I'm not quite clear on what you want.  Are you looking for a way to determine what computer any given user is logged into given only the user's username?  Or, do you want the ASP page to gather the name of the computer a user submits the page from?  I'm assuming this is on Windows.  If it's the latter, then you can grab the COMPUTERNAME environment variable.  Should it be the former, then maybe this will work: http://www.winnetmag.com/Article/ArticleID/5878/5878.html 
0
 
GitchoAuthor Commented:
gdewrell :
It's a bit of a work around, and may work, but if you can view the list of sessions in the computer manager snap for any remote logon server, you should be able to query the logon server for the same session list in VB - just like you can pull many other remote server attributes.

bluedevilfan :
I'm looking for a way to get the name(s) of the computer(s) that a user is logged onto, by passing only their network username to the program.   Let me check into that winnetmag.com link & get back to u ... thanks ...
0
 
GitchoAuthor Commented:
bluedevilfan :

you're the man !  I've been looking everywhere for that ... works awesome. thanks.
0
 
David LeeCommented:
Cool!  Glad I could help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now