make an automatic .bat file that locks the pc after 5:00PM until 6:30AM and repeats…
- User
make an automatic .bat file that locks the pc after 5:00PM until 6:30AM and repeats every 1 minute
- Assistant
To create a batch file that locks your PC every day at 5:00 PM and unlocks it at 6:30 AM, you can use the following approach. However, please note that batch files cannot directly "lock" a computer; they can run a command to lock it. Additionally, continuous locking and unlocking of a PC is not a typical or recommended operation as it could cause user inconvenience.
Here is a simple approach where we incorporate a scheduling mechanism to check the time and lock the computer if it is between those hours:
- Open Notepad or any text editor.
- Copy and paste the following code:
@echo off :loop rem Get the current time in HH:MM format for /f "tokens=1-2 delims=:" %%a in ("%time%") do ( set hour=%%a set minute=%%b ) rem Check if the current time is >= 17:00 (5 PM) and < 06:30 (6:30 AM) if %hour% GEQ 17 ( if %hour% LSS 24 ( echo Locking PC... rundll32.exe user32.dll,LockWorkStation ) ) else if %hour% LSS 6 ( if %hour% GEQ 0 ( echo Locking PC... rundll32.exe user32.dll,LockWorkStation ) ) rem Wait for 1 minute timeout /t 60 >nul goto loop - User
what is a good way to create a parental control via locking the pc after specific hours?
- Assistant
- User
I want a .bat file that locks the pc after 1 hour and 30 minutes have passed from the moment an user logs on
- Assistant
You can create a batch file that locks the PC automatically after 1 hour and 30 minutes from the moment a user logs on. Below is a sample script that you can use:
Steps to Create the Batch File
- Open Notepad or any text editor.
- Copy and Paste the following code:
@echo off setlocal rem Set the duration in seconds (1 hour and 30 minutes) set /a duration=90*60 rem Display a message indicating the timer has started echo The PC will lock in 90 minutes (1 hour and 30 minutes). rem Wait for the specified duration timeout /t %duration% >nul rem Lock the workstation echo Locking the PC now... rundll32.exe user32.dll,LockWorkStation - User
I want it to run in the background and not show up
- Assistant
To run the batch file in the background without showing the command prompt window, you can create a shortcut that starts the batch file in a minimized or hidden mode using a small VBScript. Below are the steps to accomplish this:
Step 1: Create your Batch File
- Open Notepad or another text editor.
- User
why is it 90*60
- Assistant
The expression
90*60is used to convert 90 minutes into seconds. Here's the breakdown:- 90 minutes is the duration we want to set for the lock.
- Since there are 60 seconds in a minute, to get the total number of seconds in 90 minutes, you multiply the number of minutes (90) by the number of seconds in each minute (60).
So: [ 90 \text{ minutes} \times 60 \text{ seconds/minute} = 5400 \text{ seconds} ]
This means that 90 minutes equals 5400 seconds, which is the value that the batch script uses to determine how long to wait before executing the lock command.
Summary
90is the number of minutes.60is the number of seconds per minute.- The multiplication gives you the total duration in seconds (
5400 seconds), which thetimeoutcommand uses to pause the script for that duration before proceeding to lock the workstation.