Jump to content
Sign in to follow this  

Communicating between autoit programs?

Recommended Posts


I have to write two program so that they are like this:

1. The master program can be run by all users without administrator rights, while the slave one requires admin rights.

[This can be done with #RequireAdmin written in the slave one.]

2. The users interact with the master. The master then commands the slave and the slave do the job.

["Doing the job" can be done by entering the "job" script in the slave program.]

But how can I write so that the master can COMMAND the slave? Not only that, how can the slave HEAR the commands?

Help me! I need a virtual mouth and ear, if you know what I mean.

*************More Details**********************************

1. The second autoit (slave) will have administrator rights because I want the first autoit (master) can be able to run by ALL USERS without UAC bragging, while the second one has to do jobs that requires admin rights.

2. I know how to program all but the "talking" and "hearing" part



JPGRARMouse Lock | My website | Thanks so much for your help! ❤️

Share this post

Link to post
Share on other sites

What you're trying to do is called interprocess communication. There are a few solutions:



Alternatively, you can use TCP messages locally.

Share this post

Link to post
Share on other sites


My personal favourite is this based on some code from Yashied:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Based on code from Yashied

#include <GUIConstantsEx.au3>

Opt("WinTitleMatchMode", 3)

Global Const $WM_COPYDATA = 0x004A
Global $sThis_Win_Title, $sThat_Win_Title
Global $iY, $hInput, $hButton, $hLabel
Global $sMsg_To_Send, $sMsg_Rcvd, $sMsg_Set = ""

; Set GUI title
If WinExists("First Instance") Then
    If WinExists("Second Instance") Then Exit
    $sThis_Win_Title = "Second Instance"
    $sThat_Win_Title = "First Instance"
    $iY = 300
    $sThis_Win_Title = "First Instance"
    $sThat_Win_Title = "Second Instance"
    $iY = 100

; Create GUI
GUICreate($sThis_Win_Title, 400, 150, 100, $iY)

$hInput = GUICtrlCreateInput("", 20, 20, 360, 20)
$hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30)
$hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20)



While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Send close message to other window
            _SendData(WinGetHandle($sThat_Win_Title), "@exit")
        Case $hButton
            ; Send message to other window
            $sMsg_To_Send = GUICtrlRead($hInput)
            $hWnd = WinGetHandle($sThat_Win_Title)
            If (Not @error) And ($sMsg_To_Send <> "") Then _SendData($hWnd, $sMsg_To_Send)

    ; Check messages received
    If $sMsg_Rcvd = "@exit" Then Exit
    If $sMsg_Rcvd <> $sMsg_Set Then
        GUICtrlSetData($hLabel, $sMsg_Rcvd)
        $sMsg_Set = $sMsg_Rcvd


Func _SendData($hWnd, $sData)

    Local $tCOPYDATA, $tMsg

    $tMsg = DllStructCreate("char[" & StringLen($sData) + 1 & "]")
    DllStructSetData($tMsg, 1, $sData)
    $tCOPYDATA = DllStructCreate("dword;dword;ptr")
    DllStructSetData($tCOPYDATA, 2, StringLen($sData) + 1)
    DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tMsg))
    $Ret = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($tCOPYDATA))
    If (@error) Or ($Ret[0] = -1) Then Return 0
    Return 1

EndFunc   ;==>_SendData

Func _WM_COPYDATA($hWnd, $msgID, $wParam, $lParam)

    Local $tCOPYDATA = DllStructCreate("dword;dword;ptr", $lParam)
    Local $tMsg = DllStructCreate("char[" & DllStructGetData($tCOPYDATA, 2) & "]", DllStructGetData($tCOPYDATA, 3))
    $sMsg_Rcvd = DllStructGetData($tMsg, 1)
    Return 0

EndFunc   ;==>_WM_COPYDATA

Just compile it and run it twice.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this