Skip to main content
Added to the answer for more options
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

Note that the above will only work for idle minutes, you need to make a slight amendment to it if you want to use hours of idle time before logging out the disconencteddisconnected session.

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

Alter the 23 to adjust the hours, the above will work on 24hours or more of idle time. The %%h 2012 ensures the %%d value is an hour and not a minute value.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

Note that the above will only work for idle minutes, you need to make a slight amendment to it if you want to use hours of idle time before logging out the disconencted session.

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

Alter the 23 to adjust the hours, the above will work on 24hours or more of idle time. The %%h 2012 ensures the %%d value is an hour and not a minute value.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

Note that the above will only work for idle minutes, you need to make a slight amendment to it if you want to use hours of idle time before logging out the disconnected session.

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

Alter the 23 to adjust the hours, the above will work on 24hours or more of idle time. The %%h 2012 ensures the %%d value is an hour and not a minute value.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

Note that the above will only work for idle minutes, you need to make a slight amendment to it if you want to use hours of idle time before logging out the disconencted session.

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

Alter the 23 to adjust the hours, the above will work on 24hours or more of idle time. The %%h 2012 ensures the %%d value is an hour and not a minute value.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

Note that the above will only work for idle minutes, you need to make a slight amendment to it if you want to use hours of idle time before logging out the disconencted session.

for /f "tokens=1-8 delims=,:/ " %%a in ('query user ^| find /i "disc"') do if %%d GTR 23 (if %%h GTR 2012 (logoff %%b))

Alter the 23 to adjust the hours, the above will work on 24hours or more of idle time. The %%h 2012 ensures the %%d value is an hour and not a minute value.

added 10 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

works for me in a batch file

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else (if %%e GTR 35 (logoff %%b))

This works for me in a batch file.

Source Link
MOB
  • 11
  • 1
Loading