How can my scheduled batch tell if a user is logged on?

If your scheduled batch job needs to know if a user is logged on, call UserOn.UserOn.bat returns a uon environment valiable, with a Y or N value. You can then test this variable:

Jerold Schulman

October 27, 1999

1 Min Read
ITPro Today logo in a gray background | ITPro Today


If your scheduled batch job needs to know if a user is logged on, call UserOn.

UserOn.bat returns a uon environment valiable, with a Y or N value. You can then test this variable:

call UserOn
if "%uon%"

"Y" goto UsrIsOn

 

If a user is logged on, the Shell is running. UserON.bat first determines the Shell value by running Reg and then uses tlist from the Resource kit to see if it is running.

UserOn.bat contains:

@echo offsetlocalset uon=Nfor /f "Tokens=*" %%i in ('reg -Quiet -ListValue "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogonShell"') do call :shell "%%i"endlocal&set uon=%uon%goto end:shellset sv=%1set sv=%sv:"REG_SZ =%set sv=%sv:"=%for /f "Tokens=2" %%i in ('tlist') do call :find "%%i"goto end:findif "%uon%""Y" goto endif /i "%sv%"==%1 set uon=Y:end
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like