Solved

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

Posted on 2004-08-13
7
727 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

8 Experts available now in Live!

Get 1:1 Help Now