Maelstorm Posted February 20, 2006 Posted February 20, 2006 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.
exrcizn Posted February 20, 2006 Posted February 20, 2006 Would you be interested in a vb script, or strictly command line?
Maelstorm Posted February 20, 2006 Author Posted February 20, 2006 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...
exrcizn Posted February 20, 2006 Posted February 20, 2006 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 " _& strComputerElse Wscript.Echo "No one is currently logged on at " _& strComputerEnd If Next
Maelstorm Posted February 21, 2006 Author Posted February 21, 2006 Ah yes, that was exactly what I was looking for. Here's the modified version of your script:Option ExplicitDim objWMIService, objComputer, colComputerDim strLogonUser, strLogonUser1, strComputerstrComputer = "."Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2")Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")Wscript.Echo "Users currently logged in" & vbNewLineFor 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 IfNextWscript.Echo vbNewLine & "Done." & vbNewLineAnd when I run it, I get this:E:\Deployment\Development\temp>cscript.exe login.vbsMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.Users currently logged in AdministratorDone.E:\Deployment\Development\temp>
exrcizn Posted February 21, 2006 Posted February 21, 2006 Maelstorm - Glad it worked for you and thanks for the modified code.
bledd Posted February 21, 2006 Posted February 21, 2006 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!)
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now