Jump to content

Syncronize Windows Locking (WIN+L) and Unlocking


Klaas De Smedt

Recommended Posts

Klaas De Smedt

When I lock one computer with the keybord ( WINDOWS KEY + L ). all the screens should enter the lock screen.

And in the other direction: If one computer unlocks, unlock the other computers also.

In my case, the account for both computer share the same login and password

 

You can make this an optional setting with an extra option to anly do this if the accounts on both computers are sharing the same login information?

Link to comment
Share on other sites

Chris Connelly

I don't necessarily need the synchronized unlock(although it would be nice), but if my Mac(client)'s screen locked when I press Windows+L on my Windows desktop(server) that would be really convenient.

Link to comment
Share on other sites

  • 2 months later...

I, too, would appreciate this feature as well. I know several of my officemates here have also expressed interest in this feature. Maybe include it in the list of options when setting hotkeys?

Link to comment
Share on other sites

Alex Copeland

You can tack the functionality to synchronize screen locking and unlocking with some scripting.

 

I did it with a Windows client and a Linux server. It's kind of kludgey, but the approach I took with Windows was somewhat influenced by the Windows machine being managed by group policy.

 

I don't have a Mac, but dealing with just Linux machines is a lot easier. I would imagine that Mac would be similar since you can do ssh and whatnot.

 

Anyway, on the Linux server, I had a script that ran at login on the linux box that orchestrated things. The locking of the Windows client was within a minute or so of locking the linux server.

 

#!/bin/bash
TIMEOUT_IN_MINUTES=1
TIMEOUT=$(($TIMEOUT_IN_MINUTES*60*1000))

# added comments to the /etc/synergy.conf file to hold parameters for this script
# I was only worried about 1 server and 1 client
sserver=$(grep "^#sserver" /etc/synergy.conf | sed 's/^#sserver//g')
sclient=( $(grep "^#sclient" /etc/synergy.conf | sed 's/^#sclient//g') )

# sometimes I ran a different version than the distribution, so I put which one I
# wanted to use in the config too
synergyc=$(grep "^#synergyc" /etc/synergy.conf | sed 's/^#synergyc//g')
synergys=$(grep "^#synergys" /etc/synergy.conf | sed 's/^#synergys//g')

# This is the local file location of a file that contains the state of the screen: 
# locked or unlocked.  This file is also accessible to the client.
# I chose to make it available with a web server since I was using AutoHotKey
# on my windows box.
screenstate=$(grep "^#screenstate" /etc/synergy.conf | sed 's/^#screenstate//g')

# This function locks the server turns off the screen
# It kills synergys because at least at the time if the  
# cursor was on the client screen, it wouldn't lock
# it uses slock to lock. I disabled all the distro provided screensaver
lockit() {
 killall synergys > /dev/null 2>&1 # kill synergy server
 sleep 1
 xset dpms force off                     # turn off the monitor
 echo "locked" > $screenstate      # update the file
 slock                                        # lock the screen (this will sit here until it's unlocked)
 xdotool key shift                         #simulate activity
 xset dpms force on                     # turn on the screen
 $synergys > /dev/null 2>&1        # start the synergy server
}

unlockit() {
 echo "unlocked" > $screenstate  #update the file
 killall synergys > /dev/null 2>&1 # kill it if it's still out there
 killall slock                                 # unlock the screen.  You may have to elevate to "sudo killall -9 slock"
 sleep 1                                      
 xdotool key shift                         #simulate activity
 xset dpms force on                     # turn on the screen
 $synergys > /dev/null 2>&1        # start the synergy server
}

# not a whole lot of error checking here.
# This part is mainly in here so that I could call this from keyboard shortcuts (e.g. ctl-alt-L)
# and lock the screens

while getopts ":a:" o;  do
 case $o in
   a)    action=$OPTARG     ;;
 esac
done
shift $((OPTIND-1))
case $action in
 lock) slock &;  exit 0  ;;
 unlock)  unlockit;  exit 0  ;;
esac

# do this forever
while [ 1 ];  do
 idletime=$(export DISPLAY=:0;xprintidle) # get the idle time on the main display
 ss=$(<$screenstate)                                # read the screen state information
 if [ $idletime -gt $TIMEOUT ] && [ "$ss" = "unlocked" ]
   then
   lockit 
 fi
 sleep 60
done &

tail -f $screenstate 2> /dev/null |
while read line; do
 if ps -fu $USER | grep [s]lock && [ "$line" = "unlocked" ];  then
   lockit 
 elif [ "$line" = "locked" ];   then
   unlockit 
 fi
done 

exit 0

 

 

 

On the Windows side, I did an AutoHotKey script that monitored the screenstate file by reading an html file

 

#persistent
Loop
{
screenstate := HTMLText("http:///screenstate.html", 1)
 if screenstate = locked 
   {
   Run, POWERCFG -Change -monitor-timeout-ac 1,,Hide
   Run, rundll32.exe user32.dll`,LockWorkStation,,Hide
   } 
 else 
   {
   Run, POWERCFG -Change -monitor-timeout-ac 60,, Hide
   }
 HTMLText(url, line=""){
doc := ComObjCreate("HTMLfile")
pwhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
pwhr.Open("GET",url) 
pwhr.Send()
doc.write(pwhr.ResponseText)
text := doc.body.outerText
if not line
	return, text
s := InStr(text, "`n", 0, 1, line-1)
e := InStr(text, "`n", 0, s+1)
;	return, Trim(SubStr(text, s+1, e-s-1), "`r`n")  
return, Trim(text)
 }
 Sleep, 60000

 

I also did a putty config that would run the lock or unlock command to the linux server, but I can't find that.

 

Anymore, I just run Linux on my physical machines and do what windows stuff I have to with VMs. Here's the script that I am running to synchronize screen locking on 3 linux hosts. You need to sed up passwordless ssh keys for your user between them and have sudo access the server. I am sure it's not perfect, but it suits my needs.

 

 

 

 

#!/bin/bash
#among others, you'll need: xdotool xautolock slock

export DISPLAY=:0
TIMEOUT=${2:-45}
THISSCRIPT=$0
clients="client1 client2"

ED="export DISPLAY=:0"
synergys=$(grep "^#synergys" /etc/synergy.conf | sed 's/^#synergys//g')
ctlock="$ED;echo '$ED;slock'|at now;xset dpms force off"
ctulock="$ED;sudo killall slock;xset dpms force on"
ctsynergyc="$ED;ps -ef|grep -v grep|grep -q [s]ynergyc || synergyc localhost"


case $1 in
 "start"|"-start"|"--start")
   killall xautolock
   xset s off -dpms
   xset s noblank
   killall synergys > /dev/null 2>&1
   killall -9 synergys > /dev/null 2>&1
   xdotool key shift
   xset dpms force on
   xset s off -dpms
   $synergys > /dev/null 2>&1
   for pc in $clients; do
     ssh -X $pc "$ctulock"
     ssh -X $pc "$ctsynergyc"
   done
   xautolock -time $TIMEOUT -locker $THISSCRIPT &
 ;;
 *)
   xautolock -disable
   killall synergys > /dev/null 2>&1
   killall -9 synergys > /dev/null 2>&1
   sleep 1
   xset dpms force off
   for pc in $clients; do
     ssh -X $pc "$ctlock"
   done
   slock
   xdotool key shift
   xset dpms force on
   xset s off -dpms
   xautolock -enable
   for pc in $clients; do
     ssh -X $pc "$ctulock"
     ssh -X $pc "$ctsynergyc"
   done
   $synergys > /dev/null 2>&1
 ;;
esac

exit 0

Link to comment
Share on other sites

I found an easier way, but it will require that your Mac is setup as the server and the Windows machine is the client. I found this entirely by accident, so whether or not this was intended or purely coincidental is beyond me.

 

I went in to my Screen Saver settings and set up Hot Corners so that one of the bottom corners of the screen was set to start my screen saver. Once the screen saver activated, both machines locked. You do have to set up the mac to lock immediately when the screen saver starts through Settings > Security & Privacy > General and then setting the option to require the password (choosing immediately from drop down) after sleep or screen saver begins. I haven't tested Sleep, but I'd imagine it would work as well.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...