Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get computer name from user name (or other way around)

Status
Not open for further replies.

sunaj

Technical User
Feb 13, 2001
1,474
DK
Hi,

Using Active directory I can get a list of all the users on our network. I can also get a list of all the computers. How do I get the name of the computer that a user is currently logged on to?
Or the other way around would also work for me(I could loop through all the computers to see which users aer logged on to which computers).

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
I know this is not the answer you're hoping for, and I'm sure there'll be a "proper" way of doing it, but have you considered having a program run on startup to save the username and ip when the user logs on?

 
Hi,

Nope, that was not the answer I was looking for.
I'm trying to get a list of all users currently logged on and on which pc/server they are logged on....


Any other ideas?
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
strongm answered this question for me here: thread222-92023

The technique works well when you have Administrative priveleges but if you don't and you have to use session 10 then the results were mixed on our network, which is a statewide WAN, but maybe you'd have better success if you're on a smaller one..

If you don't have success with this I can show you how to do it using shells to NET.EXE and NBSTAT, which is slow but pretty reliable.

 
hardkor1001110,

Thx. I knew I had seen an answer, but couldn't find the post.

Did you get strongm code working?
NetSessionEnum keeps returning '5' (and 0 users)... Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
hmm... so do you have admin priveleges? if not use SESSION_INFO_10. check on MSDN to make sure you have the right structure for this type. yes it did work, but not 100%, it was mixed from machine to machine, which I think has something to do with what domain you're running on, our network has dozens. at best it retrieved about 60% of the computer names for the logged in users.

also the network techs here say how sloppily our network is stiched together and problems with active directory so maybe it will work much better on your network once you get it working.

My department needed an application to locate employees on an overhead map of the building, but did not want to give my app adminstrative priveleges, and since GetSessionEnum didn't work reliably enough I had to shell to NET and NBSTAT.

I don't know why else that code wouldn't work for you. you might want to try cutting the code down to the simplest part - all you need to retrieve a single user name, and toy with it that way to get it working.

strongm is a WIN32 GURU, wait for his post...






 
>strongm is a WIN32

I blame a sad and unhealthy fascination for Charles Petzold in my younger days...

I have to admit that the code I originally posted was extracted from an administrative program I wrote that, naturally, ran with admin privileges. Whilst I know - and advised on - the necessary changes for it to work in non-admin mode I have to own up to not actually testing said changes.

If I get a chance I'll try it out, and post any corrections that I discover to be necessary.
 
HARDKOR could you post the nbtstat code , I've got a similar bit of code but sometimes I have to run it twice to get it to look at a different user ie: click once with user#1 in the entry text box coughs up their details, change user in text box to user#2 press button - still shows old details , press it again and it works - even got a routine to determine of the shelled app has finished but still get probs ? ? ?

Snorky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top