Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Environment is in domain, server is Windows Server 2003, workstations have Vista and XP installed.
I need the way to check remotely who is currently logged on workstation, preferably from some simple command line and without sysinternals or third party programs.

Thanks

share|improve this question

closed as too broad by Tom O'Connor Apr 11 at 8:58

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers 5

up vote 26 down vote accepted

see here : http://techrepublic.com.com/5208-7343-0.html?forumID=101&threadID=307918&messageID=3065346

They suggest the wmic command which available on windows :

WMIC /NODE: xxx.xxx.xxx.xxx COMPUTERSYSTEM GET USERNAME Will return the username currently logged into xxx.xxx.xxx.xxx

or WMIC /NODE: "workstation_name" COMPUTERSYSTEM GET USERNAME will return the username currently logged into "workstation_name"

share|improve this answer

Sorry, did not notice you do not want to use Sysinternals.
That is now a Microsoft technet tool, any specific reason to not use it?
I have preferred Sysinternals over other third party tools before Mark Russinovich moved into Microsoft.


The Microsoft Sysinternals Suite has a tool called Psloggedon,

psloggedon.exe -l


There is also NBTSTAT,

nbtstat -a NetBIOS-Computer-NAme
share|improve this answer
2  
sysinternals is just the business. I hope they paid Mark a ton of money to go there, currently they havn't stopped him doing the good work he was doing before and long may that continue. –  gbjbaanb Jun 27 '09 at 13:44
    
@gbjbaanb, I am happy about that. Hope he keeps updating and adding to the suite. –  nik Jun 27 '09 at 15:45

I've used win32_loggedonuser, but ran into an issue where more than one domain user was returned, so it didn't work for my purposes. Instead I used (In powershell)

#Get Currently logged in user
$ExplorerProcess = gwmi win32_process | where name -Match explorer

if($ExplorerProcess.getowner().user.count -gt 1){
    $LoggedOnUser = $ExplorerProcess.getowner().user[0]
}

else{
    $LoggedOnUser = $ExplorerProcess.getowner().user
}

the if is because sometimes getowner will report more than one user for some reason, don't know why but in my case it was the same user so it wasn't an issue.

share|improve this answer
1  
The reason is that more than one user may be logged in. Fast user switching etc. was introduced years ago. I)t keeps the other user logged on. –  TomTom Oct 18 '13 at 7:20
    
Good Point @TomTom, I forgot about that, I think [win32_loggedonuser] would also return anyone who's psexec'd or powershell'd in as well. –  BigHomie Oct 18 '13 at 13:03

You can get this info from win32_loggedonuser.

From this page:

strComputer = "."   ' " use "." for local computer

Set objWMI = GetObject("winmgmts:" _
              & "{impersonationLevel=impersonate}!\\" _
              & strComputer & "\root\cimv2")

Set colSessions = objWMI.ExecQuery _
    ("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")

If colSessions.Count = 0 Then
   Wscript.Echo "No interactive users found"
Else
   For Each objSession in colSessions
     If objSession.LogonType = 2 Then
       WScript.Echo "Logon type: Console"
     Else
       WScript.Echo "Logon type: RDP/Terminal Server"
     End If
     Set colList = objWMI.ExecQuery("Associators of " _
         & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _
         & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )

     For Each objItem in colList
       WScript.Echo "User: " & objItem.Name
       WScript.Echo "FullName: " & objItem.FullName
       WScript.Echo "Domain: " & objItem.Domain
     Next
     Wscript.Echo "Session start time: " & objSession.StartTime
     WScript.Echo
   Next
End If
share|improve this answer

why you dont use environment variable ??
in command prompt type :

echo %username%

or use whoami that give you ComputerName\UserName

share|improve this answer
    
Can this be done remotely as the OP asks? –  Flup Apr 11 at 8:18
    
@Flup you can do this by sysinternal's psexec here OR Powershell remoting or SSH –  Jeson Park Jun 17 at 16:41

protected by Community Jun 28 '11 at 16:45

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.