How to Keep Track of When You Work Using a Scheduled Task

During the day, I work as a web developer. To get paid I need to complete a time-sheet. Some weeks I’ll get to Friday and realize, “Hey! I forgot to fill in my time-sheet, and I can’t remember what hours I did this week!.” I’m sure office-goers like me can relate to this situation. 🙂

In this guide I’ll show you how I resolved this problem, by creating a scheduled task that will log the date and time when I login or lock my computer. This can help every one, including those who work from home (like this site’s editor), to accurately track the time spent in front of computer every day. The trick is Windows only.

Part One: Creating the script

Step 1. Create a folder.

Create Login Folder

Step 2. Create a new text file in that folder and name it login.bat.

To do this right a blank space in the folder and select New -> Text Document.

Create New Text Document

Name it login.bat. (Make sure it is not named login.bat.txt)

Rename To Login Dot Bat

Step 3. Open the text file and copy and paste the following code into it.

@echo off
set datecode=%date:~-4%-%date:~7,2%-%date:~4,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
if "%1"=="i" echo %datecode% - Logged in >> C:\!Scripts\Login\login.txt
if "%1"=="o" echo %datecode% - Locked computer >> C:\!Scripts\Login\login.txt

Save it!

Important Note: If you want your log file to appear somewhere different to mine, then make sure you update the path in the script.

Part Two: Creating the login task

Step 1. Open Task Scheduler, by going Start -> Run (WIN+R) and typing taskschd.msc in the prompt that appears.

Open Task Scheduler

Step 2. Select Create Task… from the actions on the right hand side.

Create Task

Step 3. Enter a task name like Log the login date and time.

Enter Login Task Name

Step 4. Click on the Triggers tab and add a new trigger. Select:

  • Begin the task: At log on
  • Specific user: This should be your Windows account
Trigger At Logon

Click OK to add the trigger.

Step 5. Add another trigger except this time select Begin the task: On workstation unlock.

Trigger At Unlock

Click OK to add the trigger.

Step 6. Click on the Actions tab. Add a new action and point it to your login script with the argument i.

Add Login Action

Click OK to add the action.

Step 7. (Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power.

Set Power Options

Click on OK to create the task.

Part Three: Creating the lock task

Step 1. In Task Scheduler, select Create Task… from the actions on the right hand side.

Create Task

Step 2. Enter a task name like Log the lock date and time.

Create Lock Task Name

Step 3. Click on the Triggers tab and add a new trigger. Select:

  • Begin the task: On workstation lock
  • Specific user: This should be your Windows account
Trigger At Lock

Click OK to add the trigger.

Step 4. Click on the Actions tab. Add a new action and point it to your login script with the argument o.

Add Lock Action

Click OK to add the action.

Step 5. (Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power.

Set Power Options

Click on OK to create the task.

Part Four: Testing that everything is working as expected

Your work is now complete. You just need to test that everything is working as expected. Just lock your computer by hitting WIN+L and log back in. If you followed the instructions properly, you should now have a file called login.txt in the same folder as your script. This file should contain a log of each time you log in and out of your computer.

Log File

Lastly, if you want to be able to access this log file quickly, you may want to follow our guide on how to use keywords to launch almost anything quickly in Windows.

Last updated on 07 February, 2022

The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.