Skip navigation

JSI Tip 5527. How can I retrieve basic user data?

I have scripted GetUserInfo.bat to retrieve basic user data. The syntax is:

call getuserinfo UserName

where UserName must be quoted if it contains any space characters.

To verify that the UserName was found, use a statement like:

if not defined $line1 goto NotFound

After verifying that the UserName was found, you can access the basic user data by using the environment variables from the following table:

Description Sample Data
$line1 User name Jerry
$line2 Full Name Jerold Schulman
$line3 Comment Sample Comment
$line4 User's comment
$line5 Country Code 000 (System Default)
$line6 Account active Yes
$line7 Account expires Never
$line8 Password last set 07/12/2002 20:27
$line9 Password expires 07/12/2002 20:27
$line10 Password changeable 07/12/2002 20:27
$line11 Password required Yes
$line12 User may change password Yes
$line13 Workstations allowed All
$line14 Logon script logon.bat
$line15 User profile profile path
$line16 Home directory home folder path
$line17 Last logon 07/15/2002 07:05

GetUserInfo.bat contains:

@echo off
if \{%1\}

\{\} goto syntax set /a cnt=0 ::NOTE: If you don't have a domain, change the following statemnt to: for /f "Tokens=*" %%i in ('net user %1') do set line=%%i&call :parse for /f "Skip=1 Tokens=*" %%i in ('net user %1 /domain') do set line=%%i&call :parse if %cnt% EQU 0 set $line1= set cnt= set line= goto :EOF :syntax endlocal @echo syntax: Call GetUserInfo "UserName" goto :EOF :parse set /a cnt=%cnt% + 1 if /i "%line%"

"The command completed successfully." goto :EOF if %cnt% GTR 17 goto :EOF set $line%cnt%=%line:~29,256%

Sample Usage

To implement a user locator for a single domain controller domain, create a Locator$ share on your domain controller granting Domain Users Read and Write permissions, and Creator Owner delete permission. Add the following code to your logon script:
call getuserinfo "%username%"
if defined $line1 del /q "%LOGONSERVER%\Locator$\%userName%.*"&"@echo %$line2% >"%LOGONSERVER%\Locator$\%userName%.%ComputerName%"
To locate a user, type:

dir "%LOGONSERVER%\Locator$\UserName.*"

Hide 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.