Skip navigation

JSI Tip 8455. Who is logged onto your domain more than once?

Using GetUsers.bat and Psloggedon freeware, I have scripted LoggedMult.bat to generate a .CSV (Comma Separated Value) file of all users who are logged into your domain from more than 1 computer.

The syntax for using LoggedMult.bat is:

LoggedMult FileName

Where FileName is the .CSV file that will be generated. The format of each line is:

"UserName","Computer1","Computer2"\[,"Computer3" .....,"ComputerN"\]

LoggedMult.bat contains:

@echo off
If \{%1\}==\{\} @echo Syntax LoggedMult FileName&goto :EOF
setlocal
set file=%1
if exist %file% del /q /f %file%
set pUser=LoggedMult
set /a cnt=0
for /f "Tokens=*" %%a in ('getusers') do ( 
 set usr=%%a
 call :where
)
endlocal
goto :EOF
:where
set /a cnt=0
for /f "Tokens=*" %%b in ('psloggedon -L -X "%usr%"^|Find "%USERDOMAIN%\%usr%"') do (
 for /f "Tokens=1* Delims=\" %%t in ('@echo %%b') do (
 set line=%%u
 call :where1
 )
)
if %cnt% LSS 2 goto :EOF
set list="%cmp1%"
set /a seq=1
:loop
set /a seq=%seq% + 1
if %seq% GTR %cnt% goto out
call set comp=%%cmp%seq%%%
set list=%list%,"%comp%"
goto :loop
:out
@echo "%usr%",%list%>>%file%
goto :EOF
:where1
For /f "Tokens=4" %%f in ('@echo %line%') do (
 set comp=%%f
)
set /a cnt=%cnt% + 1
set cmp%cnt%=%comp%



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