JSI Tip 2442. How do I produce a list of workstations and the last logged on user?


Using Netdom and Reg from the

Microsoft created a batch file for a Windows NT 4.0 domain at Knowledge Base article Q260324.

Using Netdom from a

and the freeware Reg, I have created a batch file for a Windows 2000 domain.

The syntax is LastUser <DomainName>, where LastUser.bat contains:

@echo off
cls
if "%1"

"" goto nodom set dom=%1 if exist output.txt del output.txt if exist temp.txt del temp.txt for /f "Skip=2 Tokens=1*" %%i in ('netdom query /domain:%dom% workstation') do call :parse %%i sort <temp.txt>output.txt del temp.txt goto end :parse if "%1"

"The" goto end set computer=%1 for /f "Tokens=2" %%i in ('reg -ListValue "\\%1\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName"') do set wsdom=%%i if /i "%wsdom%"=="%dom%" goto user set usr=None :pipe set computer=%computer% ! set computer=%computer:~0,25% @echo %computer% %usr% >> temp.txt goto end :user for /f "Tokens=2" %%i in ('reg -ListValue "\\%1\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName"') do set usr=%%i goto pipe :nodom echo Specify the target domain on the command line echo EXAMPLE: lastuser MyDomainName echo. :end

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish