Dos commands to find a username or computername
filed in Computers on Sep.24, 2009
To get user name in DOS batch use NET CONFIG command
Example #1
C:\net config
Computer name \\COMPUTER735
Full Computer name HomePC_Desktop
User name kris
Workstation active on
NetbiosSmb (000000000000)
NetBT_Tcpip_{CC09707A-A099-457D-BD4F-15F9F783C4C1} (00319B7A4864)
Software version Windows 2002
Workstation domain DSE
Workstation Domain DNS Name domain.co.uk
Logon domain DSE
COM Open Timeout (sec) 0
COM Send Count (byte) 16
COM Send Timeout (msec) 250
The command completed successfully.
Example #2
If your computer is in the Active Domain system net config can be used for you local pc (Workstation) or for (Server).
C:\>net config
The following running services can be controlled:
Server
Workstation
The command completed successfully.
then to find user name use workstation command:
C:\>net config Workstation
Computer name \\COMPUTER735
Full Computer name HomePC_Desktop
User name kris
Workstation active on
NetbiosSmb (000000000000)
NetBT_Tcpip_{CC09707A-A099-457D-BD4F-15F9F783C4C1} (00319B7A4864)
Software version Windows 2002
Workstation domain DSE
Workstation Domain DNS Name domain.co.uk
Logon domain DSE
COM Open Timeout (sec) 0
COM Send Count (byte) 16
COM Send Timeout (msec) 250
The command completed successfully.
Example #3
To retrieve only the user name one can use find command, this is an example:
C:\>net config | find “User name”
User name kris
Example #4
To save user name in the file “user.txt” use:
C:\>net config | find “User name” > user.txt
or
C:\>net config | find “User name” > %temp%.\user.txt
Example #5
Finally a little bit more sophisticated script for advanced users (save this code in getuser.bat file):
@echo off
SET user=
if not ‘%1==’ goto 2nd
net config workstation | find “User name” > %temp%.\getuser.bat
%temp%.\getuser.bat
:2nd pass
set user=%2
if “%user%”==”" ECHO No User name set
if not “%user%”==”" ECHO User=%user%
del %temp%.\getuser.bat
Then execute above script:
C:\>user.bat
User=kris