Hello all,
I'd like the have a on demand elevation of an filesystem COM object, so I can delete/rename/create items in the 'Program Fiels' folder.
So far I found some code about running a 'out of process' COM object with evevated rights (see code below)
But now I need some 'objects' ClassID / Interface ID etc to actually do some fiel system actions....
--------------------------------------------------------------------------- type PBindOpts3 = ^TBindOpts3; {$EXTERNALSYM tagBIND_OPTS3} tagBIND_OPTS3 = record cbStruct: DWORD; grfFlags: DWORD; grfMode: DWORD; dwTickCountDeadline: DWORD; dwTrackFlags: DWORD; dwClassContext: DWORD; locale: LCID; pServerInfo: Pointer; hwnd: hwnd; end; TBindOpts3 = tagBIND_OPTS3; {$EXTERNALSYM BIND_OPTS3} BIND_OPTS3 = TBindOpts3;
function CoGetObject(pszName: PWideChar; pBindOptions: PBindOpts3; const iid: TIID; ppv: PPointer): HResult; stdcall; external 'ole32.dll';
procedure CoCreateInstanceAsAdmin(const Handle: HWND; const ClassID, IID: TGuid; PInterface: PPointer); var BindOpts: TBindOpts3; MonikerName: WideString; Res: HRESULT; begin ZeroMemory(@BindOpts, Sizeof(TBindOpts3)); BindOpts.cbStruct := Sizeof(TBindOpts3); BindOpts.hwnd := Handle; BindOpts.dwClassContext := CLSCTX_LOCAL_SERVER;
MonikerName := 'Elevation:Administrator!new:' + GUIDToString(ClassID);
Res := CoGetObject(PWideChar(MonikerName), @BindOpts, IID, PInterface); if Failed(Res) then raise Exception.Create(SysErrorMessage(Res)); end; ---------------------------------------------------------------------------
-- Regards,
Ronald Hoek
Application Developer ComponentAgro B.V. Oud-Beijerland - The Netherlands
http://www.componentagro.nl
KvK: H24264020
Edited by: Ronald Hoek on Apr 11, 2013 1:17 AM