Question

Greetings!

Wondered about creating COM ActiveX module to the program, which will be called if necessary with elevated privileges.

To do all this using Delphi XE5 and Windows 8.1 Pro x64.

Made ActiveX Library, added COM Object, added a test function. Registered in the system, using the Run> ActiveX Server-> Register. The operation was successful.

Here are my library has a GUID:

  LIBID_libCOM: TGUID = '{B6D13396-71C2-4503-B314-65E72F176413}';
  IID_ITestOBJ: TGUID = '{0FD34325-6654-4DC4-9537-11CAA5B25652}';
  CLASS_TestOBJ: TGUID = '{1FDCEE9D-E747-4616-9D00-D55D7FD26B03}';

Object interface:

  ITestOBJ = interface (IUnknown)
    ['{0FD34325-6654-4DC4-9537-11CAA5B25652}']
    function GetSum (S1: HResult; S2: HResult): HResult; stdcall;
  end;

If you call in the usual way, then it works:

var
 II, TOBJ: ITestOBJ;
begin
 II: = CoTestOBJ.Create;
 II.QueryInterface (ITestOBJ, TOBJ);
ShowMessage (IntToStr (TOBJ.GetSum (StrToInt (Edit1.Text), StrToInt (Edit2.Text))));
end;

After that I added to the registry LocalisedString, Elevation \ Enabled, Elevation \ IconReference

Next, call the code:

var
 z: ITestOBJ;
 hr: HRESULT;

 BO: BIND_OPTS3;
 MonikerName: WideString;
begin
 hr: = 0;
 z: = nil;

 MonikerName: = 'Elevation: Administrator! New:' + GUIDToString (CLASS_TestOBJ);
 FillChar (BO, SizeOf (BIND_OPTS3), 0);

 BO.cbStruct: = SizeOf (BIND_OPTS3);
 BO.dwClassContext: = CLSCTX_LOCAL_SERVER;
 BO.hwnd: = Self.Handle;

 hr: = CoGetObject (PWideChar (MonikerName), @ BO, ITestOBJ, @ z);



 OleCheck (hr);

 ShowMessage (IntToStr (z.GetSum (1, 2)));
end;

Request comes from UAC to provide law, I click Yes.

After that, an error "Class not registered".

What am I doing wrong? After all, almost all figured out, is likely to remain small detail!

P.S.

In general, it is possible to call a COM object from a DLL library without registering it in the system and request elevation? So it was much easier to LN, and would automatically solve some kind of other problem.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top