Delphi - interprocess communication between lower-level and higher-level processes

I have a Small vcl application in delphi that runs with administrator privileges, this application only receives messages and emits mouse events. The second application works with normal user privileges (below the first), this application cannot send messages to the first application. I am sure that the reason is the privilege level, higher and lower, because if I run both lower and higher, they communicate with success. How can I make IPC, where can I send a message to a higher-level application from a lower-level application? Or is it impossible?

This is the way I use to send messages:

A higher application uses this code to process winapi.messages:

procedure TfrMouseDriver.WMCopyData(var Message: TWMCopyData); var S: WideString; cmd, sX, sY: String; s2,F: String; WParam: WideString; i, z, X, Y: integer; begin X := 1; Y := 1; if true then begin s:= PWideChar(Message.CopyDataStruct.lpData); s2:= PChar(Message.CopyDataStruct.lpData); ... 

And the lower-level application sends messages this way:

 procedure TfrPenDriver.btnIPCClick(Sender: TObject); var CopyData: CopyDataStruct; hMouse : HWND; Msg : WideString; begin Msg := 'CM_MOVE:000500:000230'; hMouse := FindWindow(PCHAR('TfrMouseDriver'),nil); if hMouse > 0 then begin CopyData.dwData := 0; CopyData.lpData := PWideChar(Msg); CopyData.cbData := (1 + Length(Msg))*SizeOf(WideChar); Winapi.Windows.SendMessage(hMouse, WM_COPYDATA, 0, LPARAM(@CopyData)); end; end; 

Im looking I am a way to make IPC between these applications with different user levels, where the lowest level needs to be sent to a higher level application.

+6
source share
1 answer

Answering incoming calls for interprocess communication on the local computer is your best choice because of their simplicity, and they are implemented through the driver in Windows, for example, in pipes. This driver is msfs.sys on NT systems. You do not need special privileges for creating mailboxes, reading / writing, etc., And they work with any type of process, application level and in any external session.

Window handles (HWNDs) are session-specific and will not work in other user sessions, so in this case you run into problems using WM_COPYDATA, as it relies on a window handle and, as already mentioned, UIPI restrictions for more modern Windows operating systems may to be a problem.

Another reason WM_COPYDATA is small is ... Suppose you are executing executable code in the context of another process (such as a system process such as csrss) that is not an "interactive" process. Perhaps you entered the DLL and want to send the IPC message using WM_COPYDATA ... You can expect the process to fail, or depending on the criticality of the process, wait for the BSOD. This is because these processes do not take into account user32.dll APIs such as SendMessage, which WM_COPYDATA relies on as an IPC system.

Stick to mailboxes.

+2
source

Source: https://habr.com/ru/post/983982/


All Articles