Microsoft KB Archive/260324

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

Article ID: 260324

Article Last Modified on 11/1/2006

-

APPLIES TO


 * Microsoft Windows NT Workstation 4.0 Developer Edition
 * Microsoft Windows NT Server 4.0 Standard Edition

-



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.  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. Create the Lastuser.bat and Lastusr2.bat files listed in the &quot;Batch Files&quot; section of this article. Create these files in the folder you created in step 1. Run the Lastuser.bat file at a command prompt. The command has the following syntax:

lastuser

 Examine the contents of the Output.txt file.



Batch Files
NOTE: You must replace the five references to  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 off cls if &quot;%1&quot;==&quot;&quot; goto nodomain set dom=%1 if exist ms.txt del ms.txt if exist output.txt del output.txt if exist out2.txt del out2.txt if exist temp.txt del temp.txt echo. echo Generating Server List of Member Servers and Workstations echo. echo Please Wait... netdom /d:%1 /noverbose member > MS.TXT echo. echo Generating List of Member Servers and Workstations - Done echo. echo List Generated. Checking Last Logged On User. for /f %%a in (ms.txt) do call lastusr2.bat %%a sort /+3 out2.txt del output.txt echo Computer NameLast Logged On User >> output.txt echo - >> output.txt type out2.txt >> output.txt if exist ms.txt del ms.txt if exist out2.txt del out2.txt if exist temp.txt del temp.txt echo. echo List is Complete. Results are in Output.txt. goto end
 * nodomain

echo Specify the target domain on the command line echo EXAMPLE: lastuser MyDomainName echo.
 * end

The Lastusr2.bat File
NOTE: The two lines in this file that begin with &quot;reg query&quot; 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 name set usr=<TAB>Machine Offline REM Next line wrapped for readability: it should all be on one line. reg query &quot;HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon \DefaultDomainName&quot; %1 | find /I &quot;defaultdomainname&quot; > temp.txt REM End of single line. for /f &quot;tokens=3 delims=<TAB>&quot; %%a in (temp.txt) do set usr=%%a REM Next line wrapped for readability: it should all be on one line. reg query &quot;HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon \DefaultUserName&quot; %1 | find /I &quot;defaultusername&quot; > temp.txt REM End of single line. for /f &quot;tokens=3 delims=<TAB>&quot; %%a in (temp.txt) do set usr=<TAB>%usr%\%%a echo %1 %usr% >>output.txt

Keywords: kbinfo kbprogramming KB260324

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.