You are currently offline, waiting for your internet to reconnect

How to Produce a List of Workstations and the Last Logged On User

This article was previously published under Q260324
SUMMARY
This article describes how to produce a text file containing a sorted list of Windows NT domain member servers and workstations with the name of the user who last logged on.
MORE INFORMATION
The method outlined in this article uses the Netdom.exe and Reg.exe tools from the Microsoft Windows NT 4.0 Resource Kit. Make sure that these tools are installed and available through the computer's PATH variable.
  1. Create a folder on the computer running Windows NT that has read/write permissions assigned to the user account you are using to log on.
  2. Create the Lastuser.bat and Lastusr2.bat files listed in the "Batch Files" section of this article. Create these files in the folder you created in step 1.
  3. Run the Lastuser.bat file at a command prompt. The command has the following syntax:
    lastuser domainname
  4. Examine the contents of the Output.txt file.

Batch Files

NOTE: You must replace the five references to <TAB> in the following two batch files with a true tab character. The easiest way to accomplish this is to edit the files with Edit.com and select where you need to insert the tab character. Press CTRL+P, and then press TAB. This action should insert an ASCII character. If you do not correct these lines before you run the files, the batch jobs do not work.

The Lastuser.bat File

@echo offclsif "%1"=="" goto nodomainset dom=%1if exist ms.txt del ms.txtif exist output.txt del output.txtif exist out2.txt del out2.txtif exist temp.txt del temp.txtecho.echo Generating Server List of Member Servers and Workstationsecho.echo Please Wait...netdom /d:%1 /noverbose member > MS.TXTecho.echo Generating List of Member Servers and Workstations - Doneecho.echo List Generated. Checking Last Logged On User.for /f %%a in (ms.txt) do call lastusr2.bat %%asort /+3 <output.txt >out2.txtdel output.txtecho Computer Name<TAB>Last Logged On User >> output.txtecho ----------------------------------------- >> output.txttype out2.txt >> output.txtif exist ms.txt del ms.txtif exist out2.txt del out2.txtif exist temp.txt del temp.txtecho.echo List is Complete. Results are in Output.txt.goto end:nodomainecho Specify the target domain on the command lineecho EXAMPLE: lastuser MyDomainNameecho.:end				

The Lastusr2.bat File

NOTE: The two lines in this file that begin with "reg query" are wrapped for readability. If you do not correct these lines before you run the file, the batch job does not work.
REM %1 = computer nameset usr=<TAB>Machine OfflineREM Next line wrapped for readability: it should all be on one line.reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName" %1 | find /I "defaultdomainname" > temp.txtREM End of single line.for /f "tokens=3 delims=<TAB>" %%a in (temp.txt) do set usr=%%aREM Next line wrapped for readability: it should all be on one line.reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName" %1 | find /I "defaultusername" > temp.txtREM End of single line.for /f "tokens=3 delims=<TAB>" %%a in (temp.txt) do set usr=<TAB>%usr%\%%aecho %1 %usr% >>output.txt				
Properties

Article ID: 260324 - Last Review: 11/01/2006 03:31:29 - Revision: 1.1

  • Microsoft Windows NT Workstation 4.0 Developer Edition
  • Microsoft Windows NT Server 4.0 Standard Edition
  • kbinfo kbprogramming KB260324
Feedback