Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sun 9-May-2010 18:16:18

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

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.

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"