Skip navigation

JSI Tip 7430. A quick way to retrieve the current user's full name in a script.


I have scripted FullName.bat to retrieve the current user's full name.

The syntax for using FullName.bat is:

FullName Name

where Name is a call directed environment variable that will contain the current user's full name.

FullName.bat determines if the current user is logged onto a domain, or logged on locally, and retrieves the full name from the domain, or local computer, accordingly.

FullName.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: Call FullName Name&goto :EOF
setlocal
if defined UserDNSDomain set dom=/domain
for /f "tokens=2*" %%i in ('net user %username% %dom% ^| find "Full Name"') do set FullName=%%j
endlocal&set %1=%FullName%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish