Skip navigation

JSI Tip 0963. List the users who are configured to "Logon To" each workstation.


Using only native commands, JSIWSWho.bat produces a sorted/formated report of each Workstation and the Users who are permitted to "Logon To" it.

The report format is:

 ComputerName1   UserName1   User1 Full Name 
 ComputerName1   UserName9   User9 Full Name 
----------------- ----------------- -----------------
 ComputerName2   UserName3   User3 Full Name 
 ComputerName2   UserName5   User5 Full Name 
 ComputerName2   UserName6   User6 Full Name 
----------------- ----------------- -----------------
 ComputerName3   UserName2   User2 Full Name 
 ComputerName3   UserName4   User4 Full Name 
 ComputerName3   UserName7   User7 Full Name 
 ComputerName3   UserName8   User8 Full Name 

To use JSIWSWho, place it in your path on the PDC:

JSIWSWho <Drive:>\Folder\OutputFile.Ext

JSIWSWho.bat contains:


@echo off
if NOT "%1"

"" goto begin :syntax @echo Syntax: JSIWSWho File goto end :begin set file=%1 set low=zzzzzzzzzzzzzzzzzzzz if exist %file% del /q %file% set tmpf=%~dpn1.WSWho if exist %tmpf% del /q %tmpf% for /f "Skip=4 Tokens=*" %%i in ('net users') do call :parse "%%i" sort %tmpf% del /q %file% set txt=%low% # set txt=%txt:~0,22% for /f "Tokens=1-3 Delims=\" %%i in (%tmpf%) do call :output %%i "%%j" "%%k" del /q %tmpf% set cnt= set low= set str= set substr= set ustr= set txt= set fullname= set file= set ws= set tmpf= goto end :output set ws=%1 set ws=%ws% # set ws=%ws:~0,22% if not "%txt%"

"%ws%" @echo ------------------------------------------------------------------------------- >> %file% set txt=%ws:~0,22% set substr=%2 set substr=%substr:"=% set substr=%substr% # set substr=%substr:~0,22% set fullname=%3 set fullname=%fullname:"=% set fullname=%fullname% # set fullname=%fullname:~0,30% @echo %ws% %substr% %fullname% >> %file% goto end :parse set str=#%1# set str=%str:#"=% set str=%str:"#=% if "%str%"

"The command completed successfully." goto end set substr=%str:~0,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end set /a cnt=0 for /f "Tokens=*" %%i in ('net user "%substr%"') do call :parse1 "%%i" set substr=%str:~25,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end set /a cnt=0 for /f "Tokens=*" %%i in ('net user "%substr%"') do call :parse1 "%%i" set substr=%str:~50,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end set /a cnt=0 for /f "Tokens=*" %%i in ('net user "%substr%"') do call :parse1 "%%i" goto end :parse1 set /a cnt=%cnt% + 1 set ustr=%1 if %ustr%

"The command completed successfully." goto end set ustr=%ustr:"=% if %cnt% EQU 2 set fullname=%ustr:~29,99% if %cnt% NEQ 13 goto end set txt=%ustr:~29,199% if "%txt%"

"All" goto end for /f "Tokens=1-8 Delims=," %%i in ('@echo %txt%') do call :Workstn %%i %%j %%k %%l %%m %%n %%o %%p goto end :Workstn if "%1"=="" goto end call :report %1 shift goto Workstn :report set ws=%1 set ws=%ws:A=a% set ws=%ws:B=b% set ws=%ws:C=c% set ws=%ws:D=d% set ws=%ws:E=e% set ws=%ws:F=f% set ws=%ws:G=g% set ws=%ws:H=h% set ws=%ws:I=i% set ws=%ws:J=j% set ws=%ws:K=k% set ws=%ws:L=l% set ws=%ws:M=m% set ws=%ws:N=n% set ws=%ws:O=o% set ws=%ws:P=p% set ws=%ws:Q=q% set ws=%ws:R=r% set ws=%ws:S=s% set ws=%ws:T=t% set ws=%ws:U=u% set ws=%ws:V=v% set ws=%ws:W=w% set ws=%ws:X=x% set ws=%ws:Y=y% set ws=%ws:Z=z% @echo %ws%\%substr%\%fullname% >> %file% if "%ws%" LSS "%low%" set low=%ws% :end

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