willichan Posted June 1, 2010 Share Posted June 1, 2010 (edited) I use Synergy-Plus in multiple locations/networks, and was getting tired of manually changing which configuration I used for each location. I now use the following script to automatically detect which network I am on, load the correct configuration file, and launch either the client or the server accordingly. This allows me to take my laptop to various client sites and use my setup for that site, while still keeping my home office setup as well. --- updated Oct. 15, 2010 to fix a bug in the 'client' launcher --- SynergyStarter.au3 expandcollapse popupOpt("MustDeclareVars", 1) Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 0) Opt("TrayIconHide", 0) Global Const $MyName = StringLeft(@ScriptName, StringInStr(@ScriptName, ".", 0, -1) - 1) Global Const $MyMutex = $MyName & "-77EC0AB9AA3BBB7B" If _MutexExists($MyMutex) Then Exit Global Const $versions[7][3] = [[6, "", ""], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Synergy", "", ""], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\The Synergy+ Project\synergy-plus 1.4.1", "", "bin"], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\The Synergy+ Project\synergy-plus 1.4.0", "", "bin"], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\The Synergy+ Project\synergy-plus 1.3.5", "", "bin"], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\The Synergy+ Project\synergy-plus 1.3.4", "", "bin"], _ ["HKEY_LOCAL_MACHINE\SOFTWARE\Synergy", "Install_Dir", ""]] Global $AppPath = _GetAppPath() Global $ConfName = "synergy.conf" Global $IniFile = $MyName & ".ini" Global $ConfigFile = $AppPath & $ConfName Main() Exit Func Main() Local $i, $inf, $j Local $configs = IniReadSection($IniFile, "configs") For $i = 1 To $configs[0][0] $inf = StringSplit($configs[$i][1], "|") If $inf[0] <> 2 Then ContinueLoop If $inf[2] = $ConfName Then ContinueLoop $j = Ping($configs[$i][0], 5000) If $j > 0 Then Switch StringLower($inf[1]) Case "server" FileCopy(@ScriptDir & "\" & $inf[2], $ConfigFile, 1) Sleep(500) Run('"' & $AppPath & 'synergys.exe" --config "' & $ConfigFile & '" --no-daemon --debug FATAL', $AppPath, @SW_HIDE) ExitLoop Case "client" Run('"' & $AppPath & 'synergyc.exe" --no-daemon --debug FATAL ' & $configs[$i][0], $AppPath, @SW_HIDE) ExitLoop Case Else ContinueLoop EndSwitch EndIf Next EndFunc ;==>Main Func _GetAppPath() Local $res, $ret, $i $ret = @ScriptDir For $i = 1 To $versions[0][0] $res = RegRead($versions[$i][0], $versions[$i][1]) If Not @error Then $ret = $res If StringRight($ret, 1) <> "\" Then $ret &= "\" $ret &= $versions[$i][2] If StringRight($ret, 1) <> "\" Then $ret &= "\" ExitLoop EndIf Next Return $ret EndFunc ;==>_GetAppPath Func _MutexExists($sOccurenceName) Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError $sOccurenceName = StringReplace($sOccurenceName, "\", "") $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName) $lastError = DllCall("kernel32.dll", "int", "GetLastError") Return $lastError[0] = $ERROR_ALREADY_EXISTS EndFunc ;==>_MutexExists Credit to martin for the _MutexExists function. (Thanks JRowe for the correction) Here is a sample INI file: SynergyStarter.ini [configs] ;machine=type|config server1=server|srv1.sgc server2=server|srv2.sgc machine3=client|cli3.sgc 'machine' is the name of a system to look for that is unique to that network. The first match found will be used. The machine name provided must be able to answer a PING. 'type' is the type of Synergy session to launch. This can only be 'server' or 'client'. 'config' is the name of the config file to use for this session. It will be copied to 'synergy.conf' for server sessions, or passed on the command line for client sessions. The config file must be in the same folder as the script. This was an effective, yet quick and dirty solution. Any suggestions for improvement will be appreciated. Edited January 24, 2011 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
JRowe Posted June 1, 2010 Share Posted June 1, 2010 _MutexExists is martin's work, I believe. Nice job, this will be great for my netbook. Thanks! [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
FuryCell Posted June 1, 2010 Share Posted June 1, 2010 (edited) This is awesome. I actually just started using Synergy+ and that is one of things that bothered me about it. Nice work. Edited June 1, 2010 by FuryCell HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
willichan Posted June 3, 2010 Author Share Posted June 3, 2010 I am glad someone besides me finds it useful. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
willichan Posted July 2, 2010 Author Share Posted July 2, 2010 I have updated and cleaned up the Synergy Launcher a bit. The top post has been updated to contain the most up-to-date code. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Farqy Posted September 18, 2010 Share Posted September 18, 2010 I have updated and cleaned up the Synergy Launcher a bit. The top post has been updated to contain the most up-to-date code.This is exactly what I was looking for. Thanks a million. It was getting especially annoying when I would get home and start VPN and my laptop and desktop and work would link up. Now hopefully with your script my home pc's and my work laptop will connect instead.Anyways thanks for the work. Link to comment Share on other sites More sharing options...
willichan Posted October 15, 2010 Author Share Posted October 15, 2010 Latest update (see post #1) fixes a bug in the way that synergyc.exe was being launched. It was not getting the correct parameter. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
willichan Posted January 24, 2011 Author Share Posted January 24, 2011 Post #1 updated to support the newly released v 1.3.6 of Synergy. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now