I need to print the full name of the current user in the console, I have this code that does what I need but only partially
NET USER %username% /DOMAIN | FIND /I "Full name" >tmp.txt
set /p VAR=<tmp.txt
echo %VAR%
del tmp.txt
Because the result of the print is for example "Full Name Juan Perez" And the only thing I need is "Juan Perez"
Is there a way to do what I need?
CodePudding user response:
Theoretically,
@ECHO OFF
SETLOCAL
FOR /f "tokens=2*delims= " %%b IN ('NET USER %username% /DOMAIN 2^>nul ^|find /I "Full name"') DO SET "var=%%c"
ECHO Full name : "%var%"
GOTO :EOF
but NET USER %username% /DOMAIN returns an error for me.
The 2^>nul redirects errors. the ^ before > and | tells cmd the character is part of the '-enclosed command to be executed, not of the for itself.
Documentation for for can be found by executing for /? from the prompt, or reading thousands of examples on SO
