We help IT Professionals succeed at work.
Get Started

Find out computer name given the username

vsmusic2000 asked
Last Modified: 2012-05-07
Hi Experts,

I have got this script from the internet. I want to find out which computer a user is logged on to given the domain username of the person.
This script uses the net send command along with the nbtstat -c command to get the computer name and IP.
Can you please verify that it does so. I am not very good with scripting.
I am getting a compile error when I try and run this.
Thank you experts.
@echo off
if "%OS%" == "" goto syntax
if %1z == z? set goto syntax
if %1z == z set /p UN=Enter UserName: &goto main
set UN=%1
net send "%UN%" "Finding your computername. Press OK - do NOT respond." >nul
if errorlevel == 1 goto error
nbtstat -c > %TEMP%\LOCATE.LOG
findstr /i /c:%UN% %TEMP%\LOCATE.LOG >%TEMP%\LOCATE2.LOG
FOR /F "tokens=3,4,5,6,7 delims=. " %%i in (%TEMP%\LOCATE2.LOG) do ping -a -n 1 -l 1 %%j.%%k.%%l.%%m >%TEMP%\LOCATE.LOG
FOR /F "eol=: tokens=2" %%a in (%TEMP%\LOCATE.LOG) do @echo %UN% is logged into %%a&goto end
Echo This does not report whether %UN% is logged into multiple workstations!
goto end
echo Error: %UN% username not found
goto end
echo Syntax %0 username
echo Must be run from Windows NT or Windows 2000
echo NT/2000 users located, Win9x only if winpopup loaded.
goto end

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 48 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE