%username% scheduled task

  • Thread starter Thread starter Barry
  • Start date Start date
B

Barry

Hello,

Not sure if this is the right group, but its the closeset one i could find
and hope one of you can give me a hand!

I'm having trouble running a scheduled batch file involving %username%.
Mainly, it doesnt actaully return the username of whoever is logged on, it
seems to be set to whomever the scheduled task is running as.

Anyone know of any work arounds??

Thanks
 
Hello,

Not sure if this is the right group, but its the closeset one i could find
and hope one of you can give me a hand!

I'm having trouble running a scheduled batch file involving %username%.
Mainly, it doesnt actaully return the username of whoever is logged on, it
seems to be set to whomever the scheduled task is running as.

Anyone know of any work arounds??

Thanks
use PsLoggedOn from tip 2890 in the 'Tips & Tricks' at http://www.jsiinc.com

for /f "Skip=6 Tokens=3" %%u in ('c:\util\psloggedon -l^|Findstr /i /v /l
/c:"Error:"') do set Who=%%u
REM The above two lines are 1 line.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Hello,

Not sure if this is the right group, but its the closeset one i could find
and hope one of you can give me a hand!

I'm having trouble running a scheduled batch file involving %username%.
Mainly, it doesnt actaully return the username of whoever is logged on, it
seems to be set to whomever the scheduled task is running as.

Anyone know of any work arounds??

Thanks

This works better:

for /f "Skip=6 Tokens=3*" %%u in ('psloggedon -l^|Findstr /i /v /l /c:"Error:"')
do set p1=%%u&set p2=%%v
REM The above 2 lines are 1 line
set who=%p1%
if "%p1%" EQU "AM" set who=%p2%&goto finish
if "%p1%" EQU "PM" set who=%p2%
:finish



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Jerold Schulman said:
This works better:

for /f "Skip=6 Tokens=3*" %%u in ('psloggedon -l^|Findstr /i /v /l /c:"Error:"')
do set p1=%%u&set p2=%%v
REM The above 2 lines are 1 line
set who=%p1%
if "%p1%" EQU "AM" set who=%p2%&goto finish
if "%p1%" EQU "PM" set who=%p2%
:finish



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com

ahhha thanks, halfway there... now, how do i get rid of the computer name in
var p1?

cheers
Barry
 
nothanks! said:
ahhha thanks, halfway there... now, how do i get rid of the computer name in
var p1?

For what it's worth, on XP, psloggedon returns "local service",
"network service", and "system" for services configured to log on
with those accounts. You can add some more exclusions like below if
it helps:

for /f "Skip=6 Tokens=3*" %%u in ('psloggedon -l^|Findstr /i /v /l
/c:"Error:"'^|Findstr /i /v /l /c:"service"^|Findstr /i /v /l
/c:"system"') do set p1=%%u&set p2=%%v
REM The above 2 lines are 1 line
set who=%p1%
if "%p1%" EQU "AM" set who=%p2%&goto finish
if "%p1%" EQU "PM" set who=%p2%
:finish
echo Logged on: %WHO%

ws
 
ahhha thanks, halfway there... now, how do i get rid of the computer name in
var p1?

This is what I use at work. It is 1 line.

for /f "tokens=2 delims=\" %%a in ('psloggedon -l ^| find /v "Unknown"
^| find "\"') do set user=%%a


Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
This is what I use at work. It is 1 line.

for /f "tokens=2 delims=\" %%a in ('psloggedon -l ^| find /v "Unknown"
^| find "\"') do set user=%%a

This one is simpler for U.S. formatted dates.

for /f "tokens=2 delims=\" %%a in ('psloggedon -l ^| find "/"') do set
user=%%a


Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
Clay said:
This one is simpler for U.S. formatted dates.

for /f "tokens=2 delims=\" %%a in ('psloggedon -l ^| find "/"') do set
user=%%a
For international use, relying on the time separator this 2 liner does:

for /f "tokens=2 delims=\" %%a in (
'psloggedon -l^|findstr /r ":..:"') do set user=%%a


HTH
 
Back
Top