user541597
user541597

Reputation: 4345

getting username from computer network name

I have a list of ips that I use to get the computer names for these ips. I was wondering if there is anyway in c# to tie the computer name to the logged in user to that computer or vice versa. Any ideas would be appreciated.

Upvotes: 0

Views: 304

Answers (2)

Justin
Justin

Reputation: 3397

I never found a way to enumerate all users that are logged in, fast-switching or terminal server, but you can use WMI and query the processes (Win32_Process) to get the owner of the explorer.exe process. This will tell you who is actively logged into the local machine.

Upvotes: 1

Alexei Levenkov
Alexei Levenkov

Reputation: 100527

You need to enumerate sessions on each machine and pick one (or many) you like. Note that it would require box admin privileges (i.e. running as domain admin). See C# - List of Logon Sessions for details.

Note that result will be many-to-many mapping.

Upvotes: 0

Related Questions