Tuesday, February 2, 2010

Find Computer name through username

If you want to search computer name of a system on network through its username what you have to do is copy this script and paste it on notepad save it with any name but extension should be .bat or .cmd forexample: "username.cmd"


@ECHO OFF

:GETUSERNAME
ECHO.
SET UName=
SET /P UName=Enter Username for %USERDOMAIN%:
IF [%UName%]==[] (
ECHO Please provide username.
CALL :GETUSERNAME)

NET USER "%UName%" /DOMAIN 2>NUL>NUL
IF ERRORLEVEL 1 (
ECHO Username not found in Active Directory.
GOTO :GETUSERNAME)

ECHO Please wait... &ECHO.
FOR /F "delims=\\ " %%c IN ('NET VIEW ^|FIND "\\"') DO (
PING -n 1 -l 10 -w 100 %%c |FIND /I "TTL" >NUL
IF NOT ERRORLEVEL 1 (
REG QUERY "\\%%c\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName |FIND /I "%UName%" >NUL
IF NOT ERRORLEVEL 1 ECHO %UName% is logged onto %%c))

ECHO.
PAUSE
FOR /L %%v IN (1,1,24) DO ECHO.
PAUSE


:ENDSCRIPT
EXIT

5 comments:

Junaid said...

What after username.cmd???

Farjad Arshad said...

After creating username.cmd just double click it will ask you the username and returns the system name on which this user is logged on

Ganesh said...

THANK U!

it is working fine

g@nesh

Adam Preston said...

Which parts of the script need to be changed? i.e. Where do I put in the username and domain names

Adam Preston said...

Hi, Where do I need to put in the actual user name and domain name?