C:\_G\WWW\~ELISANET\INFO\tscmd167.html
<http://www.elisanet.fi/tsalmi/info/tscmd167.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Thu 25-Oct-2018 10:08:45

 
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.
  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.
Windows Task Manager

References/Comments:
  Lockfile

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd167.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd167
http://www.elisanet.fi/tsalmi/info/tscmd167.html
file:///c:/_g/www/~elisanet/info/tscmd167.html