Jump to content

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


Maelstorm

Recommended Posts

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.

Link to comment
Share on other sites


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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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