Ads
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get LastBootUpTime /value') do set "boot=%%a"
set /a uptime=%date% - %boot:~0,8%
if %uptime% LSS 2 goto end
:start
rundll32.exe user32.dll,LockWorkStation
timeout /t 180
goto start
:end
wmic
command to retrieve the date and time of the last boot up time. It then calculates the number of days since the last boot up time and compares it to 2 days. If the computer has not been turned on for at least 2 days, the script will not lock the computer and will end. If the computer has been turned on for at least 2 days, the script will lock the computer every 3 minutes until it is stopped.
Ads
Ads
This script will lock the computer using the
LockWorkStation
function and wait for 180 seconds (3 minutes) before relocking the computer. The script will keep looping and relocking the computer every 3 minutes until it is stopped.