Skip navigation

JSI Tip 7805. How can a scheduled job determine who is logged on locally?

Using PsLoggedOn, I have scripted LLO.BAT to determine what user is logged on locally.

The syntax for using LLO.BAT is:

call LLO who \[DomainOrComputer\]

Where who is a call directed environment variable that will contain the the logged on user, or will NOT be set if no one is logged on. DomainOrComputer is an optional call directed environment variable that will be set to the domain or computer that the user is logged onto, and Who will NOT have the leading DomainOrComputer\.

NOTE: If I am the logged on user, Who would be set to JSIINC\Jerry, unless you used the DomainOrComputer parameter, in which case Who would be set to Jerry and DomainOrComputer would be set to JSIINC. If the user is NOT logged onto a domain account, DomainOrComputer would be set to their computer name.

Sample Usage:

call LLO who
if not defined who goto none
:: Processing for logged on user
:none

         OR

set who=#
call LLO who
if "%who%" EQU "#" goto none
:: Processing for logged on user
:none

LLO.BAT contains:

@echo off
if \{%1\}

\{\} @echo Syntax LLO Who&exit /b 1 setlocal for /f "Tokens=3*" %%u in ('psloggedon -l^|Find /i /v "Error:"^|Find /i /v "Unknown"^|Find "\"') do set p1=%%u&set p2=%%v set who=%p1% if defined P2 set who=%p2% if \{%2\}

\{\} endlocal&set %1=%who%&exit /b 0 set dorc= if defined who for /f "Tokens=1* Delims=\" %%a in ('@echo %who%') do set dorc=%%a&set who=%%b endlocal&set %1=%who%&set %2=%dorc% exit /b 0



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