This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
167} How do I find out who is logged on the system?
There is a special freeware third-party utility
PsLoggedOn
on PsTools by Mark Russinovich available from Microsoft TechNet Windows Sysinternals.
To some extent the following pure script solution can be used to
emulate UNIX who
@echo off & setlocal enableextensions
for /f "tokens=7 delims=," %%a in ('
tasklist /v /fo csv^|
findstr /i /c:"explorer.exe"') do (
echo %%~a)
endlocal & goto :EOF
The output could be e.g.
C:\MyXPSCRIPTS>who
ULPU\tsneti
ULPU\Guest
Solved slightly differently
@echo off & setlocal enableextensions
for /f "tokens=3* delims=: " %%a in ('
tasklist /v /fi "ImageName eq explorer.exe" /fo list^|
find /i "User Name: "') do echo.%%a
endlocal & goto :EOF
The method can also be used as a first attempt to find out what
program is currently accessing (and thus locking) a particular
file. For example:
tasklist /v /fo csv|findstr /i /c:"tscmd167.pdf"
The fields in the above are
"Image Name","PID","Session Name","Session#","Mem Usage","Status","User Name","CPU Time","Window Title"
Now wile this is on a command-line FAQ it serves to note that the
questing is easily answered using GUI Windows Task Manager, provided
having admin rights.