Automatic PC lock when your Bluetooth device disconnects
NearLock monitors a paired Bluetooth device (like your phone) and automatically locks your Windows PC when you walk away. When you return and your device reconnects, you simply unlock your PC as usual.
- Bluetooth Classic & BLE detection - Works with both classic Bluetooth and Bluetooth Low Energy devices
- System tray application - Runs quietly in the background with status indicator
- First-run wizard - Easy setup to select your Bluetooth device
- Live log viewer - Monitor connection status in real-time
- Start on boot - Optional automatic startup with Windows
- Low resource usage - Minimal CPU and memory footprint
- Single instance - Prevents multiple instances from running
- NearLock continuously monitors the connection status of your selected Bluetooth device
- When the device disconnects (you walk away), a countdown starts (default: 20 seconds)
- After the countdown, a confirmation scan is performed to avoid false positives
- If the device is still not detected, your PC is automatically locked
- When you return and your device reconnects, simply unlock your PC normally
- Windows 10/11 (64-bit recommended)
- Bluetooth adapter enabled on your PC
- Paired Bluetooth device (phone, smartwatch, etc.)
- PowerShell 5.1+ (included with Windows 10/11)
⚠️ Important: Phone Link Required for Reliable DetectionFor reliable presence detection, your phone must be connected via Phone Link (Mobile Connecté). Simply having Bluetooth enabled is not enough - modern phones don't continuously advertise their presence to save battery.
Setup Phone Link:
- Install "Link to Windows" app on your phone
- Open Phone Link on your PC (pre-installed on Windows 10/11)
- Pair your phone following the instructions
- Keep Phone Link running for continuous Bluetooth connection
- Download
NearLock.exefrom the Releases page - Place it in a folder of your choice (e.g.,
C:\Program Files\NearLock) - Run
NearLock.exe - Follow the first-run wizard to select your Bluetooth device
- Clone this repository
- Run
NearLock-Single.ps1with PowerShell:powershell -ExecutionPolicy Bypass -File NearLock-Single.ps1
NearLock runs in the system tray with a colored eye icon indicating status:
| Icon Color | Status |
|---|---|
| 🟢 Green | Device connected |
| 🟠 Orange | Searching for device |
| ⚫ Grey | Disabled or no device configured |
- Auto-lock: Enabled/Disabled - Toggle automatic locking on/off
- Settings... - Change Bluetooth device or configure startup options
- View Logs - Open live log window to monitor activity
- Exit - Close NearLock
Access settings from the tray menu to:
- Change Device - Select a different paired Bluetooth device
- Start on boot - Enable/disable automatic startup with Windows
- PowerShell 5.1 or later
- ps2exe (for compiling to EXE)
-
Clone the repository:
git clone https://github.com/baptisteba/NearLock.git cd NearLock -
Install ps2exe (if not already installed):
Install-Module ps2exe -Scope CurrentUser
-
Compile to EXE:
Invoke-ps2exe -inputFile "NearLock-Single.ps1" -outputFile "NearLock.exe" -noConsole -title "NearLock" -version "1.2.1.0"
Configuration is stored in %LOCALAPPDATA%\NearLock\config.json:
{
"deviceMAC": "AA:BB:CC:DD:EE:FF",
"deviceName": "My Phone",
"startOnBoot": true
}Logs are stored in %LOCALAPPDATA%\NearLock\logs\.
NearLock uses multiple detection methods for reliability:
- Bluetooth Classic API - Uses Windows
bthprops.cplto check device connection status (requires Phone Link) - BLE GATT Proximity - Uses WinRT to attempt GATT connection with uncached mode for accurate presence detection
- Radio Scan - Performs active Bluetooth inquiry as fallback confirmation before locking
| Parameter | Default | Description |
|---|---|---|
| Poll interval | 4 seconds | How often to check device status |
| Lock threshold | 20 seconds | Time before locking after disconnect |
| Grace period | 30 seconds | Delay after system wake before monitoring |
- Uses Windows native
LockWorkStation()API to lock the PC - No network communication - all processing is local
- No data collection or telemetry
- Ensure your Bluetooth device is paired in Windows Settings
- Make sure Bluetooth is enabled on both your PC and device
- Try re-pairing the device
If NearLock locks your PC while you're still nearby:
- Your device may have intermittent Bluetooth connectivity
- Try moving closer to your PC
- Check for Bluetooth interference from other devices
If you notice high CPU usage:
- Check the logs for repeated errors
- Try restarting NearLock
- Ensure your Bluetooth driver is up to date
MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Inspired by the macOS/iOS Near Lock app
- Uses Windows Bluetooth APIs via P/Invoke
- Built with PowerShell and Windows Forms