AutoLock is a smart, automated security utility for Windows. It monitors your smartphone's Wi-Fi proximity and your PC's activity (keyboard & mouse movement) to automatically lock your workstation when you step away with your phone. It also features full remote control and status notifications via a Telegram Bot.
AutoLock operates using three main mechanisms:
-
Phone Proximity Detection (Ping):
- AutoLock periodically pings your phone's Wi-Fi IP address.
- If your phone disconnects or goes out of Wi-Fi range, failed ping count increases.
-
User Inactivity Tracking (
iohook):- Listens for global mouse movement and key presses to accurately measure idle time.
- If no activity is detected for 15+ seconds, the system is marked as Idle.
-
Automated System Lock & Notifications:
- Warning: If your phone is missing and you are idle for 3 intervals (~6 seconds), AutoLock sends a Telegram notification:
"Laptop will lock soon". - Locking: If your phone remains unreachable (4 failed pings) and you are idle, AutoLock locks Windows using
rundll32.exe user32.dll,LockWorkStationand notifies your Telegram:"laptop Locked". - Auto Reset: When your phone returns and user activity resumes, the lock state automatically resets.
- Warning: If your phone is missing and you are idle for 3 intervals (~6 seconds), AutoLock sends a Telegram notification:
-
Telegram Remote Control:
- Send
Lockto your Telegram Bot to immediately lock your laptop from anywhere. - Send
statusto check whether your laptop is currently locked or unlocked.
- Send
- Node.js (JavaScript Runtime)
ping: ICMP ping probing for local network phone detection@tkomde/iohook: Global keyboard and mouse event listeneraxios: Telegram Bot API integration for notifications and remote pollingchild_process: Native Windows workstation locking via system commands
AutoLock/
│── index.js # Main monitoring script & Telegram bot loop
│── keys.js # Private credentials (Git-ignored)
│── keys.example.js # Template file for setting up keys.js
│── package.json # Project metadata & dependencies
│── .gitignore # Excludes node_modules & keys.js
└── README.md # Project documentation
git clone https://github.com/GarvSaxena/AutoLock.git
cd AutoLocknpm install- Copy
keys.example.jsto createkeys.js:cp keys.example.js keys.js
- Open
keys.jsand enter your Telegram Bot Token and Chat ID:module.exports = { token: "YOUR_TELEGRAM_BOT_TOKEN", chat_id: "YOUR_TELEGRAM_CHAT_ID" };
Open index.js and set your smartphone's static/reserved Wi-Fi IP address:
const phoneip = "192.168.1.50"; // Replace with your phone's IPnpm start
# OR
node index.jsTo make AutoLock start automatically when you log into Windows, choose one of the following methods:
-
Press
Win + R, typeshell:startup, and press Enter. This opens your Windows Startup folder. -
Create a new file named
autolock.vbsin that folder. -
Paste the following script into
autolock.vbs(replace the path with your actual AutoLock folder path):Set WshShell = CreateObject("WScript.Shell") WshShell.Run "node ""C:\Users\YOUR_USERNAME\Desktop\AutoLock\index.js""", 0, False
-
Save the file. AutoLock will now run silently in the background every time Windows starts.
- Install PM2 globally and
pm2-windows-startup:npm install -g pm2 npm install -g pm2-windows-startup pm2-startup install
- Start AutoLock with PM2:
pm2 start index.js --name "autolock" pm2 save
- Open Task Scheduler from the Windows Start menu.
- Click Create Task... on the right panel.
- Under the General tab:
- Name:
AutoLock - Check "Run only when user is logged on"
- Name:
- Under the Triggers tab:
- Click New... -> Select At log on -> Click OK.
- Under the Actions tab:
- Click New... -> Program/script:
node - Add arguments:
index.js - Start in:
C:\Users\YOUR_USERNAME\Desktop\AutoLock
- Click New... -> Program/script:
- Click OK to save.
Garv Saxena