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. 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. Name it login.bat. (Make sure it is not named login.bat.txt) Step 3. Open the text file and copy and paste the following code into it. @echo offset 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.txtif “%1”==“o” echo %datecode% - Locked computer » C:!Scripts\Login\login.txt Save it!

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. Step 2. Select Create Task… from the actions on the right hand side. Step 3. Enter a task name like Log the login date and time. Step 4. Click on the Triggers tab and add a new trigger. Select:

Begin the task: At log onSpecific user: This should be your Windows account

Click OK to add the trigger. Step 5. Add another trigger except this time select Begin the task: On workstation 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. 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. 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. Step 2. Enter a task name like Log the lock date and time. Step 3. Click on the Triggers tab and add a new trigger. Select:

Begin the task: On workstation lockSpecific user: This should be your Windows account

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. 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. 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. 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. 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.

How to Keep Track of When You Work Using a Scheduled Task - 53How to Keep Track of When You Work Using a Scheduled Task - 39How to Keep Track of When You Work Using a Scheduled Task - 90How to Keep Track of When You Work Using a Scheduled Task - 6How to Keep Track of When You Work Using a Scheduled Task - 53How to Keep Track of When You Work Using a Scheduled Task - 37How to Keep Track of When You Work Using a Scheduled Task - 55How to Keep Track of When You Work Using a Scheduled Task - 34How to Keep Track of When You Work Using a Scheduled Task - 7How to Keep Track of When You Work Using a Scheduled Task - 44How to Keep Track of When You Work Using a Scheduled Task - 70How to Keep Track of When You Work Using a Scheduled Task - 9How to Keep Track of When You Work Using a Scheduled Task - 29How to Keep Track of When You Work Using a Scheduled Task - 70How to Keep Track of When You Work Using a Scheduled Task - 31How to Keep Track of When You Work Using a Scheduled Task - 12How to Keep Track of When You Work Using a Scheduled Task - 21How to Keep Track of When You Work Using a Scheduled Task - 56How to Keep Track of When You Work Using a Scheduled Task - 20How to Keep Track of When You Work Using a Scheduled Task - 63How to Keep Track of When You Work Using a Scheduled Task - 79How to Keep Track of When You Work Using a Scheduled Task - 25How to Keep Track of When You Work Using a Scheduled Task - 22