Lock Windows 11 Remotely Using Sleepwatcher Mac
In this guide, we will walk you through the process of remotely locking a Windows 11 computer from your Mac using sleepwatcher. This will require SSH access to your Windows machine configured with a public key instead of a password. Follow these steps to set up remote locking:
Prerequisites
-
SSH Configuration: Ensure that you have SSH access to your Windows 11 computer from your Mac, and it is set up to use a public key for authentication instead of a password. If you haven’t set up SSH with public key authentication, you can find guides online for this process.
-
Homebrew: Make sure you have Homebrew installed on your Mac. If you don’t have it, you can install it by following the instructions on the Homebrew website.
Setup Lock Task
-
Create a Task in Task Scheduler:
On your Windows 11 machine, open Task Scheduler and create a new task with the following settings:
- Action: Start a program
- Program/script:
rundll32.exe - Add arguments (optional):
user32.dll,LockWorkStation
Save the task with a name, e.g., “Lock.”
Install sleepwatcher
-
Install sleepwatcher with Homebrew:
Open your Terminal on your Mac and run the following command to install
sleepwatcher:1brew install sleepwatcher
Configure sleepwatcher
-
Create a Configuration File for sleepwatcher:
Create a new file named
.sleepin your home directory (usually/Users/yourusername/) using a text editor like Vim. Replaceyourusernamewith your actual username. Use the following command:1vim ~/.sleepAdd the following content to the
.sleepfile:1 2#!/bin/bash ssh yourusername@your-windows-pc schtasks /RUN /TN "Lock"Make sure to replace
yourusernamewith your Mac’s username andyour-windows-pcwith the hostname or IP address of your Windows 11 PC. -
Modify sleepwatcher Configuration:
Edit the
sleepwatcherconfiguration file using Vim. Run the following command:1vim /usr/local/Cellar/sleepwatcher/2.2.1/homebrew.mxcl.sleepwatcher.plistFind the line that says
<string>-s</string>and replace it with<string>-D</string>. This change ensures thatsleepwatcherruns in the background.
Start sleepwatcher Service
-
Start the sleepwatcher Service:
Start the
sleepwatcherservice using the following command:1brew services start sleepwatcherThis will initiate the
sleepwatcherservice and make it run automatically in the background.
Lock Windows 11 Remotely
Now, whenever your Mac goes to sleep, sleepwatcher will execute the .sleep script, which in turn will SSH into your Windows 11 machine and run the Task Scheduler task, locking your Windows 11 session remotely.
With these steps, you can remotely lock your Windows 11 computer from your Mac using sleepwatcher and SSH with public key authentication.