Delphi: application running as admin does not receive messages from non-admin app

做~自己de王妃 提交于 2020-03-05 04:05:00

问题


I want to send messages to another application, using SendMessage/PostMessage, but when the other app is running as admin it never receives the messages. How can I overcome this without running the "sending" app as admin?

EDIT: code for Remi's answer, receiver app

Const dummyValue = WM_USER + 71423;

  Application.HookMainWindow(AppClass.AppHookFunc);
  ChangeWindowMessageFilter(dummyValue, MSGFLT_ADD);

Type TAppClass = class
  function AppHookFunc(var Message : TMessage): Boolean;
end;

Var AppClass: TAppClass;

function TAppClass.AppHookFunc(var Message : TMessage): Boolean;
begin
  Result := False;
  Case Message.Msg of
    dummyValue: begin
      // do stuff
      //
      Result := True;
    end;
  end;
end;

回答1:


User Interface Privilege Isolation (UIPI) prevents a lower integrity process from sending window messages to a higher integrity process. The only ways you can deal with this limitation from a software perspective are to either:

  • run your sending app at a higher integrity level (ie, run it with elevated privileges) to match the target process.

  • if you have access to change the source code for the receiving app, make it opt-in to receive specific window messages from lower integrity processes, by calling ChangeWindowMessageFilter() or ChangeWindowMessageFilterEx() on itself.

  • have your sending app bypass UIPI, by requesting uiaccess=true in its <requestedExecutionLevel> application manifest element. However, this has additional requirements:

    • The app must be digitally signed with a certificate that can be verified with a root certificate installed on the machine.

    • the app must be installed in a "secure" folder on the filesystem 1 (one that standard users can't write to) under %ProgramFiles% and its subdirectories, or under %WinDir% and its subdirectories (except a few subdirectories that standard users do have write access to).

      1: this requirement is configurable via a system policy.

Outside of software control, the only other option available requires changing system policies to disable User Account Control (UAC) and/or UIPI altogether at the system level. Which you should not do.



来源:https://stackoverflow.com/questions/56051274/delphi-application-running-as-admin-does-not-receive-messages-from-non-admin-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!