Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

RemoteAHK - Execute AHK scripts on remote computers (TCP/IP)


  • Please log in to reply
26 replies to this topic
TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
As the title says, RemoteAHK allows you to remotely execute AHK scripts using TCP/IP. This is done through the use of AHKsock.

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!

Benjamin K.
  • Members
  • 7 posts
  • Last active: Jul 04 2010 08:50 AM
  • Joined: 26 Sep 2006
Nice script!

But seems not to work if the pc running the server.ahk is locked.

So for example you start RemoteAHK - Server and then lock the pc.
If you then try to run the test script that shows the parameters you won't get any Message Box when logging in again.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Do you log off or only lock the computer?
For me, the message box generated while locked was there when I unlocked the computer. If you log off, the server will be terminated.

gha1d
  • Members
  • 21 posts
  • Last active: May 30 2013 04:53 PM
  • Joined: 10 Feb 2007
Can i use it to send a files contents to be displayed on a remote PC like this

Loop
{
FileRead, Contents, C:\Num.txt
if ErrorLevel
break
gui, font, s9
Gui, Show, x55 y66 w310 h150,HT-Detect
Gui, Add, Text,, Numbers for %A_Hour%:%A_min%:%A_Sec%
Gui, Add, Text,, %Contents%:
Gui, Submit, NoHide
Gui, Show
}

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
This looks cool. Couple of questions.

I would guess you would need to open the port your using on the firewalls of both machines, is this correct? If so does leaving this port open make the computer vulnerable to attacks?

And does the computer sending the file have to be running AHK or could it be from other TCP/IP software?
http://www.wincesoft...control_ii.html

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

Can i use it to send a files contents to be displayed on a remote PC like this

Well, RemoteAHK only sends a script file, so you would need to either include the data to display inside the script to send, or you would send the data beforehand and have the script load it over there.

I would guess you would need to open the port your using on the firewalls of both machines, is this correct? If so does leaving this port open make the computer vulnerable to attacks?

If both machines are behind a router (on the same LAN), then you shouldn't have to open any ports (maybe just add an exception if you're running software firewalls). But if you want this to work over the Internet, then yes, you'll need to forward ports on your router. Personally, I wouldn't do that, because if (not probable) someone knows you're running a RemoteAHK server, he could execute any scripts he wants on the target machine.

You could modify the server to add some sort of 'restriction' (eg. a password as the first line of your script that the server will look for before executing it).

And does the computer sending the file have to be running AHK or could it be from other TCP/IP software?

They're only compatible with each other because I designed the 'protocol.' (It's the same one used in the file sending examples of AHKsock).

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
I should read up on AHKsock but in this case before I get too involved I'm just going to ask. :lol:

Could a script be written using AHKsock that would communicate with other TCP/IP software like in the link before?

And I hate to bring this up here but while I have your attention. If you haven't seen it already would you mind looking at my request for help concerning AHKHID?
http://www.autohotke...pic.php?t=66499

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Sorry for the late response. I had seen your post earlier, but forgot to get back to it.

Could a script be written using AHKsock that would communicate with other TCP/IP software like in the link before?

Not sure what you mean. I quickly looked at the product, and it seems like communication goes one way (from the "remote control" to the device).
Did you want to write a software that does the same thing?

If you haven't seen it already would you mind looking at my request for help concerning AHKHID?

I will take a look at it.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Not sure what you mean. I quickly looked at the product, and it seems like communication goes one way (from the "remote control" to the device).Did you want to write a software that does the same thing


Actually yes, that is what I want to do. Be able to launch AHK subroutines through a network connection from an old Ipaq. I haven't had time to stop and look into it yet so I don't have a clue of how much trouble it will be so I was hoping you could clue me in on what I'm getting into.

I want to get the IR side of it working with AHK too but WINLIRC isn't compatible with my transceiver. But that's another topic.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

Be able to launch AHK subroutines through a network connection from an old Ipaq.

If the Ipaq can run AHK and can see the target machine, then it would be a piece of cake with RemoteAHK.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Be able to launch AHK subroutines through a network connection from an old Ipaq.

If the Ipaq can run AHK and can see the target machine, then it would be a piece of cake with RemoteAHK.


Actually I think there is a spin off of AHK that I can run on an Ipaq. I'm not sure but I think IronAHK may be able to also.

But I was asking about the Remote Control ll software I posted a link to above. It's like sending a command line with parameters over HTTP. It's built into the software to connect to remote webservers such as in EventGhost.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

But I was asking about the Remote Control ll software I posted a link to above.

Sorry, I'm still not clear on what you're trying to do. Do you want to build something that will send commands just like your software above, or something that will receive the commands from RCII? Or both?

The easiest option would be "both." The problem with implementing just one half of the conversation is that you would have to learn the language the other uses, which is not easy.

With RemoteAHK, you don't have to worry about any of this. Basically, you would just have to put whatever command you want to execute in a script, and send that script file using the RemoteAHK client. On the target machine, the RemoteAHK server will execute the AHK script as soon as it is received.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
I'm just wanting to see if it was possible to make a script the would receive commands from RCll. I think making an app to replace RCll on the ipaq would be quite difficult.

Right now this is just a thought I'm not ready to try it yet, just saw this thread and wondered if this would be what I would use when I got ready to try. When the time comes I'll read up on everything I can find then ask questions.

By the way, I'm getting some help making a library for the more advanced HID dll you showed me. We just started last night so I'm not sure how it's going to work out.

Thanks again for your help.

lordkrandel
  • Members
  • 32 posts
  • Last active: Jul 17 2013 12:47 PM
  • Joined: 12 Dec 2010
Merging AHKremote with Autohotkey.dll could bring us to a full AHKserver.
An hypotetical AHKserver.exe would dynamically load Autohotkey.dll
and listen to commands coming from a socket.
Commands would be proxy for the DLL functions.

Your program --JSON req--> { "ahkFunction" : script } --network-->
--> AHKServer --> execution --> return value ---network---> Your program

This would also enable all languages to interact remotely with Autohotkey,
with no CDECL problem or anything.

Ref: https://ahknet.autoh...otkey/index.htm

Security should not be an issue at all. If you listen to AHK commands,
you simply should NOT be accessible from the network, unless there was
a proper user authentication/login/encryption layer that no one has implemented yet.

cholya
  • Members
  • 13 posts
  • Last active: Feb 22 2011 04:32 PM
  • Joined: 29 Dec 2010
Hi all, I have a problem to run Client ahk script on remote PC.

Run, "%A_AhkPath%" "D:\AutoHotkey\TCP_IP\RemoteAHK - Client.ahk" 192.168.243.39:27015 D:\AutoHotkey\TCP_IP\test_message.ahk Hello_world

D:\AutoHotkey\TCP_IP\test_message.ahk:
>>>>>>>>>
MsgBox, %1%
<<<<<<<<<

On remote PC (A_Temp "\RemoteAHKtmp.ahk"):
Contain text: "M s g B o x" - with extra spaces and without input parameter "Hello_world"

Where I'm wrong?