Solved

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

Posted on 2004-08-13
7
730 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now