Jump to content

[Help] How do you see who is logged in?


Recommended Posts

Posted

Is there a way, from the command line, to find out who is logged into a computer remotely? I can telnet into a machine to get a command prompt on that machine, but I don't know the command to see who is logged in. I'm looking for the Windows equivilent to the Unix who command, if that helps.


Posted

It doesn't matter as long as it prints out on the command line, otherwise I will not be able to see it. That is the only requirement: must display on the command line. I'm doing this remotely through telnet. If you have a vbscript, then I could probably modify it to print on the command line using wscript.echo...

Posted

Here's the script. Hope you can make it work for you.

Option Explicit

Dim objWMIService, objComputer, colComputer

Dim strLogonUser, strLogonUser1, strComputer

strComputer = "."

strComputer = InputBox("Enter Computer name", _

"Find Logon User", strComputer)

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" _

& strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _

("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer

If not objComputer.UserName = "" Then

strLogonUser = Split(objComputer.UserName,"\")

strLogonUser(1) = UCase(Left(strLogonUser(1),1))_

& Trim(Mid(strLogonUser(1),2,20))

Wscript.Echo strLogonUser(1) & " is logged on at " _

& strComputer

Else

Wscript.Echo "No one is currently logged on at " _

& strComputer

End If

Next

Posted

Ah yes, that was exactly what I was looking for. :thumbup Here's the modified version of your script:

Option Explicit

Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

Wscript.Echo "Users currently logged in" & vbNewLine
For Each objComputer in colComputer
If not objComputer.UserName = "" Then
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1)) & Trim(Mid(strLogonUser(1),2,20))
Wscript.Echo vbTab & strLogonUser(1)
Else
Wscript.Echo vbTab & "None."
End If
Next
Wscript.Echo vbNewLine & "Done." & vbNewLine

And when I run it, I get this:

E:\Deployment\Development\temp>cscript.exe login.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Users currently logged in

Administrator

Done.


E:\Deployment\Development\temp>

Posted

you can just use psloggedon from the pstools pack and run it from your own machine (assuming you have an account on the pc, or know the admin pass!)

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...