Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-08-13
7
734 Views
Last Modified: 2008-01-09
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
Comment
Question by:Gitcho
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Gary Dewrell
ID: 11798829
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
 
LVL 5

Author Comment

by:Gitcho
ID: 11800723
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
 
LVL 12

Expert Comment

by:Gary Dewrell
ID: 11802543
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 11802642
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
 
LVL 5

Author Comment

by:Gitcho
ID: 11802693
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
 
LVL 5

Author Comment

by:Gitcho
ID: 11813444
bluedevilfan :

you're the man !  I've been looking everywhere for that ... works awesome. thanks.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11814294
Cool!  Glad I could help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question