How it works:
RemoteAHK contains a client and a server script. The server script must be running on the remote machine to which you wish to connect. You can specify a port number as a parameter when running the server script. Otherwise, it defaults to port 27015.
Then, using the client script, you can connect to the server and ask it to run a specified script located on the client machine. This is done through command-line parameters (there is no GUI).
The parameter syntax to run the client script is:
(Mandatory parameters are in <>. Optional parameters are in [])
<Server Address[:Port]> <Path to script[?]> [Parameter 1] [Parameter 2] ...If no port is specified, it defaults to 27015. The ? symbol can be added to the end of the path of the script to ask the server to wait for the script to finish and to return the exit code. The client will then exit with the same exit code. The parameters following the script's path will be passed to the script as parameters upon execution.
Requirements:
AHKsock
Simple file functions
You will have to uncomment the #Include lines in the RemoteAHK server and client scripts if you place the above required scripts in the same directory as opposed to in a lib directory.
Download:
RemoteAHK - Server
RemoteAHK - Client
You can use the following test script to see if it works. It will enumerate the parameters that it was passed and will return as exit code the number of parameters passed.
iParamCount = %0% If iParamCount { Loop % iParamCount sParams .= "Parameter " A_Index " = " %A_Index% (A_Index = iParamCount ? "" : "`n") MsgBox %sParams% } Else MsgBox No parameters passed! Exit, iParamCount
Example:
So for example, if you wanted to run a script, located locally at C:\MyScript.ahk, on the server located on machine 192.168.0.100 on port 8798, you would do:
Run, "%A_AhkPath%" "<Path to RemoteAHK - Client.ahk>" 192.168.0.100:8798 C:\MyScript.ahk MyScriptArgument1 MyScriptArgument2
If you also wanted to retrieve the exit code (notice the question mark):
RunWait, "%A_AhkPath%" "<Path to RemoteAHK - Client.ahk>" 192.168.0.100:8798 C:\MyScript.ahk[color=red]?[/color] MyScriptArgument1 MyScriptArgument2 iExitCode := ErrorLevel
Don't forget to put command-line arguments in quotation marks if they contain spaces.
Enjoy!