JSI Tip 6532. Freeware GetUserInfo.exe.
April 3, 2003
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 2002Usage: 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 jsiincBKP_Oper /p, the program displayed:
GetUserInfo V02.06.00cpp Joe Richards ([email protected]) June 2002User information for jsiincBKP_Oper (\JSI001)User Name BKP_OperFull Name BKP_Oper ScheduleDescriptionUser's CommentUser Type AdminEnhanced AuthorityAccount Type GlobalWorkstationsHome DirectoryUser ProfileLogon ScriptFlags NO_PWD_EXPIREAccount Expires NeverPassword age in days 232Password last set 8/14/2002 5:20 AMBad PWD count 0Num logons (this machine) 257Last logon 2/4/2003 7:57 PMLogon hours AllPrimary group Domain UsersGlobal group memberships *Domain Admins *Domain UsersLocal group memberships *Administrators *Backup Operators
I 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 Operators
NOTE: 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=3set /a cnt2=4set /a cnt=22:LoopGcall set line=%%$line%cnt%:~0^,99%%if not "%Line:~0,1%" EQU "*" goto Localset Global%cnt1%=%line:~0,24%set Global%cnt2%=%line:~24,24%set /a cnt1=%cnt1% + 1set /a cnt2=%cnt2% + 1set /a cnt=%cnt% + 1goto LoopG:Localset Local1=%line:~27,24%set Local2=%line:~51,24%set /a cnt1=3set /a cnt2=4set /a cnt=%cnt% + 1:LoopLcall set line=%%$line%cnt%:~0^,99%%if not "%Line:~0,1%" EQU "*" goto Finishset Local%cnt1%=%line:~0,24%set Local%cnt2%=%line:~24,24%set /a cnt1=%cnt1% + 1set /a cnt2=%cnt2% + 1set /a cnt=%cnt% + 1goto LoopL:Finish
GetUserData.bat contains:
@echo offif {%1}=={} set $line1=ERROR&goto :EOFset /a cnt=0set user=%1call :doit>>nul 2>>&1set /a cnt=%cnt% + 1for /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:doitfor /f "Skip=2 Tokens=*" %%a in ('getuserinfo.exe %user% /p') do set line=%%a&call :parsegoto :EOF:parseif /i "%line%" EQU "Completed." goto :EOFif %CNT% GTR 0 goto foundif not "%line:~0,9%" EQU "User Name" set $line1=ERROR&goto :EOF:foundset /a cnt=%cnt% + 1set $line%cnt%=%line%
About the Author
You May Also Like