In tip 5527, I scripted GetUserInfo.bat.
Joe Richards has written a freeware program to perform this function. It extracts more information than the standard NET USER command that I had used.
Download GetUserInfo.zip (at the bottom of this page) and extract the GetUserInfo.exe program to a folder in your path.
When you type getuserinfo /?, you receive:
GetUserInfo V02.06.00cpp Joe Richards ([email protected]) June 2002 Usage: GetUserInfo \[(domain)(\\servername)\\]userid \[/p\] domain Domain to execute command against server Server to execute command against userid Userid to get info for. /p Displays primary group info. If domain/server not specifed uses local machine If . specified for userid, enumerate all local/global accounts This software is Freeware. Use it as you wish at your own risk. If you have improvement ideas, bugs, or just wish to say Hi, I receive email 24x7 and read it in a semi-regular timeframe. You can usually find me at [email protected]When I typed getuserinfo jsiinc\BKP_Oper /p, the program displayed:
GetUserInfo V02.06.00cpp Joe Richards ([email protected]) June 2002 User information for jsiinc\BKP_Oper (\\JSI001) User Name BKP_Oper Full Name BKP_Oper Schedule Description User's Comment User Type Admin Enhanced Authority Account Type Global Workstations Home Directory User Profile Logon Script Flags NO_PWD_EXPIRE Account Expires Never Password age in days 232 Password last set 8/14/2002 5:20 AM Bad PWD count 0 Num logons (this machine) 257 Last logon 2/4/2003 7:57 PM Logon hours All Primary group Domain Users Global group memberships *Domain Admins *Domain Users Local group memberships *Administrators *Backup OperatorsI have scripted GetUserData.bat to return the following environment variables:
$line1=User Name BKP_Oper $Line2=Full Name BKP_Oper Schedule $Line3=Description $Line4=User's Comment $Line5=User Type Admin $Line6=Enhanced Authority $Line7=Account Type Global $Line8=Workstations $Line9=Home Directory $Line10=User Profile $Line11=Logon Script $Line12=Flags NO_PWD_EXPIRE $Line13=Account Expires Never $Line14=Password age in days 232 $Line15=Password last set 8/14/2002 5:20 AM $Line16=Bad PWD count 0 $Line17=Num logons (this machine) 257 $Line18=Last logon 2/4/2003 7:57 PM $Line19=Logon hours All $Line20=Primary group Domain Users $Line21=Global group memberships *Domain Admins *Domain Users $Line22=Local group memberships *Administrators *Backup OperatorsNOTE: If $Line1 is equal to ERROR, the account was NOT found.
NOTE: Starting with $line22, the output becomes variable based upon the number of Global and Local group memberships. If $line22 starts with an *, it is a continuation of the previous line.
NOTE: To extract the data from a non-continuation line, use the following example:
set UserID=%$line1:~27,99%
Set FullName=%$line2:~27,99%
etc..
To extract Group membership, use the following example:
set Global1=%$line21:~27,24% set Global2=%$line21:~51,24% set /a cnt1=3 set /a cnt2=4 set /a cnt=22 :LoopG call set line=%%$line%cnt%:~0^,99%% if not "%Line:~0,1%" EQU "*" goto Local set Global%cnt1%=%line:~0,24% set Global%cnt2%=%line:~24,24% set /a cnt1=%cnt1% + 1 set /a cnt2=%cnt2% + 1 set /a cnt=%cnt% + 1 goto LoopG :Local set Local1=%line:~27,24% set Local2=%line:~51,24% set /a cnt1=3 set /a cnt2=4 set /a cnt=%cnt% + 1 :LoopL call set line=%%$line%cnt%:~0^,99%% if not "%Line:~0,1%" EQU "*" goto Finish set Local%cnt1%=%line:~0,24% set Local%cnt2%=%line:~24,24% set /a cnt1=%cnt1% + 1 set /a cnt2=%cnt2% + 1 set /a cnt=%cnt% + 1 goto LoopL :FinishGetUserData.bat contains:
@echo off if \{%1\}==\{\} set $line1=ERROR&goto :EOF set /a cnt=0 set user=%1 call :doit>>nul 2>>&1 set /a cnt=%cnt% + 1 for /l %%x in (%cnt%,1,29) do if defined $line%%x set $line%%x= for %%x in (user cnt line) do set %%x= goto :EOF :doit for /f "Skip=2 Tokens=*" %%a in ('getuserinfo.exe %user% /p') do set line=%%a&call :parse goto :EOF :parse if /i "%line%" EQU "Completed." goto :EOF if %CNT% GTR 0 goto found if not "%line:~0,9%" EQU "User Name" set $line1=ERROR&goto :EOF :found set /a cnt=%cnt% + 1 set $line%cnt%=%line%