-3

How to identify which user is currently using the VM. That is the VM might have common login like administrator, test1 etc., but I want know which user/machine has launched the VM using mstsc from their machine and using it.

I want to fetch these information using C# or powershell code.

All the machines and VM's are in same domain.

All your suggestions are welcome.

Mohan Kumar
  • 6,008
  • 6
  • 28
  • 36
  • 3
    with 1294 reputation, you should know by now that you need to demonstrate a minimal understanding of the question you are asking. What code have you tried yet? Have you attempted to google: C#.NET tell who is on VM – logixologist Oct 04 '13 at 18:11
  • Try this link: http://stackoverflow.com/questions/2727393/get-user-sid-from-logon-id-windows-xp-and-up – logixologist Oct 04 '13 at 18:13
  • @logixologist you haven't got my ques. I know to fetch the users who is in VM. But in my case, say only one user is created in my VM (administrator). So u can login as only administrator. So whatever ans u suggested will fetch administrator is in VM. But i want from which machine/user has launched the mstsc and entered the VM via common administrator login? Hope u got it – Mohan Kumar Oct 09 '13 at 15:49

1 Answers1

0

In PowerShell you could do this:

$sessions = gwmi -cn myvm -Query "Select * from Win32_LogonSession Where LogonType = 10"
$sessions | Foreach {gwmi -cn myvm -Query "Associators of {Win32_LogonSession.LogonID='$($_.LogonId)'} Where AssocClass=Win32_LoggedOnUser Role=Dependent"}
Keith Hill
  • 194,368
  • 42
  • 353
  • 369