var
ElevatedObject2,
ElevatedObject: IElevationDemoObject;
CoGetClassFactoyAsAdmin(
GetForegroundWindow,
CLASS_ElevationDemoObject,
IID_IElevationDemoObject,
ElevatedObject); <<-- Fehler
if ElevatedObject.CreateInstance(
nil,IID_IElevationDemoObject,IUnknown(ElevatedObject2)) = S_OK
then
ElevatedObject2.DoTest;
....
procedure CoGetClassFactoyAsAdmin(
const ParentWindowHandle: HWND;
const ClassId: TGUID;
const IID: TGUID;
out ObjectInterface);
begin
CoCreateInstanceAsEx(
'
Elevation:Administrator!clsid:', ParentWindowHandle, ClassId, IID, ObjectInterface);
end;
procedure CoCreateInstanceAsEx(
const MonikerSequence : WideString;
const ParentWindowHandle: HWND;
const ClassId: TGUID;
const IID: TGUID;
out ObjectInterface);
var
MonikerName : WideString;
BindOptions : TBindOpts3;
Token : TJwSecurityToken;
iLen : Cardinal;
begin
Token := TJwSecurityToken.CreateTokenEffective(TOKEN_QUERY
or TOKEN_READ);
try
if Token.RunElevation = 0
then
begin
MonikerName := MonikerSequence + GUIDToString(ClassId);
iLen := SizeOf(TBindOpts3);
FillChar(BindOptions, iLen, 0);
BindOptions.cbStruct := iLen;
BindOptions.dwClassContext := CLSCTX_LOCAL_SERVER;
BindOptions.hwnd := ParentWindowHandle;
OleCheck(CoGetObject(PWideChar(MonikerName), @BindOptions, IID, ObjectInterface));
end
else
begin
OleCheck(CoCreateInstance(ClassID,
nil, CLSCTX_ALL, IID, ObjectInterface));
end;
finally
Token.Free;
end;
end;