troubleshooting Question

Find out computer name given the username

Avatar of vsmusic2000
vsmusic2000 asked on
VB Script
48 Comments1 Solution1221 ViewsLast Modified:
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


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 48 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 48 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros