February 20, 200620 yr 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.
February 20, 200620 yr Author 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...
February 20, 200620 yr 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
February 21, 200620 yr Author 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>
February 21, 200620 yr 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!)
Create an account or sign in to comment