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

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

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

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

  1. Install sleepwatcher with Homebrew:

    Open your Terminal on your Mac and run the following command to install sleepwatcher:

    1
    
    brew install sleepwatcher

Configure sleepwatcher

  1. Create a Configuration File for sleepwatcher:

    Create a new file named .sleep in your home directory (usually /Users/yourusername/) using a text editor like Vim. Replace yourusername with your actual username. Use the following command:

    1
    
    vim ~/.sleep

    Add the following content to the .sleep file:

    1
    2
    
    #!/bin/bash
    ssh yourusername@your-windows-pc schtasks /RUN /TN "Lock"

    Make sure to replace yourusername with your Mac’s username and your-windows-pc with the hostname or IP address of your Windows 11 PC.

  2. Modify sleepwatcher Configuration:

    Edit the sleepwatcher configuration file using Vim. Run the following command:

    1
    
    vim /usr/local/Cellar/sleepwatcher/2.2.1/homebrew.mxcl.sleepwatcher.plist

    Find the line that says <string>-s</string> and replace it with <string>-D</string>. This change ensures that sleepwatcher runs in the background.

Start sleepwatcher Service

  1. Start the sleepwatcher Service:

    Start the sleepwatcher service using the following command:

    1
    
    brew services start sleepwatcher

    This will initiate the sleepwatcher service 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.

0%