Synergy Client “When Computer Starts” Fix

If you use the wonderful tool Synergy to share your keyboard and mouse over the network, you have probably noticed that starting with Windows Vista and now Windows 7 that setting the client to run “When Computer Starts” no longer works like it did with XP. Unfortunately, this project has become unmaintained so I updated the source code to work with Vista/Win7 now. Note, setting the Synergy Server to run “When Computer Starts” is still broken and will cause your mouse to freeze, maybe I’ll look into that bug too.

Here’s the fix. Unzip and replace the three files into your Synergy folder under Program Files. This is distributed under the current license of Synergy.
Download: Synergy.zip

Also, check out Synergy+ as they are now working on this project.

Source code: diff of changes to Synergy2 tag 1.3.1.

Technoblable

Some people think that Synergy stopped working as a service, i.e. not being able to type in your user name and password at the log in prompt, because Vista had created a better security model. This is just not correct, as it would be impossible to protect your computer at this screen if you have installed a program with admin rights. That’s why it’s so important to know what programs you put on your computer, if you install something with admin privileges it basically has full access to your computer minus encrypted data. That’s just how OS are, even Linux is susceptible as soon as you install a program with sufficient privileges.

What changed starting with Vista was how Windows Services have access to your desktop. Services are things designed to run in the background of your PC, but they still could create a window on your screen. Microsoft wanted to separate the Services from the user, so they create a Windows Session for services. Windows Sessions are basically a logged in user, so on your Vista/Win7 machine right now there are at least two sessions: Session 0 for services and Session 1 for the first user logged into the system. In XP, services and the first logged in user both shared Session 0.

How this broke Synergy is that the synergy client service is started in Session 0 and connects to that desktop. You can actually access this desktop by forcing a window to appear there; use psexec tool and run something like psexec -s -i 0 mspaint.exe. You’ll be prompted about an Interactive Service and if you click on the button to view the message you’ll see a shell that looks like Windows 95, mspaint running, and your Synergy Client will work here! Synergy can also be broken in a similar manor on Windows XP. On XP, enable fast user switching and switch to a new account. You’ll notice that Synergy no longer works as this user is running in Session 1.

The fix to get this working is to have the service start the Synergy Client in the user’s session. This can be done using the function CreateProcessAsUser. To get this working I used the following strategy.

Starting a Service’s Process in User’s Session

ImpersonateSelf to assign LocalSystem’s access token to the calling thread.
OpenThreadToken to get the access token.
WTSGetActiveConsoleSessionId to get the user session ID, this is most usually just 1.
SetTokenInformation to change the LocalSystem’s Session ID from 0 to the user’s Session ID.
CreateProcessAsUser to launch the Synergy Client.

I edited Synergy2 tag version 1.3.1. To see all of my changes and a more detailed explaination of the above referer to the function CArchDaemonWindows::createProcessOnCurrentSession() in my Synergy Client fix diff file.

Unfortunately, this either caused a regression or exposed a bug in the Synergy Server code. If you try and run the server as a service, when you move the mouse to switch screens the mouse will stop working. The keyboard will work and you can escape to the host pc by pressing ctrl+alt+delete. The guys at Synergy+ are working on a fix to the client and server service issues.

Leave a Reply

You must be logged in to post a comment.